usestatebot
v1.1.3
Published
A finite state machine React hook
Downloads
8
Readme
useStateBot
A finite state machine React hook
Install
npm install --save usestatebot
or
yarn add usestatebot
Usage
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>
);
};
License
MIT © terzhang