Closed jvgeee closed 3 years ago
You can try using the "key" functionality from React.
https://reactjs.org/docs/lists-and-keys.html#keys
Pseudo-code:
const [currentRoute, setCurrentRoute] = React.useState()
history.listen(() => setCurrentRoute(route))
<WizardComponent key={currentRoute} />
It can be a solution because, when the key changes, React will throw away the previous component instance and recreate another one from scratch. That should effectively reset the Wizard.
Perfect! That solves it, sounds like it was more of a React implementation problem than a step-wizard problem. Cheers @resolritter !
I have 6 pages, each of which has a step-wizard on them.
It's something similar to this:
The
introduction
andtips
objects come from props, based on the current app route and represent an entirely different wizard; they just reuse the same component.If I'm on step 5 of a wizard, and then I click my nav to go to a different wizard, it opens step 5 of that wizard.
What am I doing wrong here? Is there a way to unmount or reset the wizard on URL change? To add complication, I have conditional steps (based on answers from previous steps) that sometimes show / hide a screen, so I don't want to reset the wizard whenever any children change.
I'm thinking there should be some sorta way to reset the wizard using
useEffect()
, but I'm a bit lost here.