-
Notifications
You must be signed in to change notification settings - Fork 0
Little Sate Machine
David Verduzco edited this page Sep 8, 2021
·
1 revision
This is only used because React Hook Forms requires it to work with Routes Wizard.
View repo here - https://github.com/bluebill1049/little-state-machine
$ npm install little-state-machine
StateMachineProvider
This is a Provider Component to wrapper around your entire app in order to create context.
<StateMachineProvider>
<App />
</StateMachineProvider>
createStore
Function to initialize the global store, invoked at your app root (where <StateMachineProvider />
lives).
function log(store) {
console.log(store);
return store;
}
createStore(
{
yourDetail: { firstName: '', lastName: '' } // it's an object of your state
},
{
name?: string; // rename the store
middleWares?: [ log ]; // function to invoke each action
storageType?: Storage; // session/local storage (default to session)
},
);
This hook function will return action/actions and state of the app.
const { actions, state } = useStateMachine<T>({
updateYourDetail,
});