UNPKG

@state-management/state-machine-react

Version:

React wrapper for simple-state-machine, provides fromState and useDispatcher hooks and unit test fixtures

14 lines (13 loc) 438 B
import { useCallback } from 'react'; import { StateMachine } from '@state-management/simple-state-machine'; /** * Custom hook for dispatching commands in the state machine. * @returns A function to dispatch commands to the state machine. */ function useDispatcher() { const dispatch = useCallback((command) => { StateMachine.getInstance().dispatch(command); }, []); return dispatch; } export default useDispatcher;