useEventState

This hook save last emitted event data in state and return state.

If You want use hooks, hocs or component decorator You must use EventrixProvider in Your application. Go to "EventrixProvider" page in "Context" section for more details.

import React from 'react';
import { useEventState, useEmit } from 'eventrix';

const UndoDeleteUserButton = () => {
    const [eventState, setEventState] = useEventState('removeUser');
    const emit = useEmit();
    const addUser = useCallback(() => {
        emit('addUser', eventState);
        setEventState(null);
    }, [emit, eventState, setEventState]);
    if (!eventState) {
        return null;
    }
    return (
        <button onClick={addUser}>
            Undo user delete
        </button>
    );
}

Last updated