A finite state machine React hook
npm install --save usestatebot
or
yarn add usestatebot
import React from 'react';
import useStateBot from 'usestatebot';
const App = () => {
const stateBot = useStateBot({
initialState: 'idle',
idle: { to: 'loading' },
loading: { to: 'ready' },
ready: {
onEnter() {
return console.log('I am ready');
},
},
});
return (
<div>
{stateBot.getState()}
<button onClick={() => stateBot.next()}>Next State</button>
</div>
);
};
MIT © terzhang