Skip to content

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

📦 Installation

$ npm install little-state-machine

🕹 API

****

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)
  },
);

useStateMachine

This hook function will return action/actions and state of the app.

const { actions, state } = useStateMachine<T>({
  updateYourDetail,
});
Clone this wiki locally