Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Created February 13, 2021 17:19
Show Gist options
  • Save hypeJunction/856413ed21686abb5f4ba9c10659acca to your computer and use it in GitHub Desktop.
Save hypeJunction/856413ed21686abb5f4ba9c10659acca to your computer and use it in GitHub Desktop.
export const StateMachineContext = React.createContext()
export function StateMachine ({
states,
initialContext,
initialState,
children,
}) {
const [context, setContext] = useState(initialContext)
const [state, setState] = useState(initialState)
return (
<StateMachineContext.Provider
value={{
context,
state,
setContext,
setState,
states,
}}
>
{children}
</StateMachineContext.Provider>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment