-
-
Save sr-shifu/b048502a02e548260e3c7885ff34afea to your computer and use it in GitHub Desktop.
State machine wizard Context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const StateMachineWizardContext = createContext({}); | |
export const StateMachineWizard = (/* props goe here */) => { | |
const contextValue = useMemo( | |
() => ({ | |
errors, | |
setStepData, | |
setErrors, | |
navigateTo, | |
}), | |
[errors, setStepData, setErrors, navigateTo] | |
); | |
// ... in the modal body | |
<StateMachineWizardContext.Provider value={contextValue}> | |
<WizardSteps | |
wizardNavHistory={navHistory} | |
wizardDataByStep={wizardDataByStep} | |
curStepName={curStepName} | |
/> | |
</StateMachineWizardContext.Provider> | |
} | |
// use this hook on client's step component side | |
export const useStateMachine = () => { | |
// TODO: handle some common common logic | |
return React.useContext(StateMachineWizardContext); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment