Comments (3)
Hi,
thanks a lot for your thoughtful comment. I really appreciate the effort you put into this :-)
The main idea about this library is that it will manage the state of the wizard and let the user decide anything else like how the form state is stored or how components are rendered.
For the example you've mentioned, I made the decision that only the active component should be mounted.
Now there lies the problem for you. Every time a component is unmounted (i.e. is not the currently active step) it loses its state.
Knowing this will leave us with a couple of possible solutions.
- Don't unmount the components when they're not visible but hide them using CSS.
https://codesandbox.io/s/wizard-custom-abstraction-forked-3rt3u
This will keep the state around but it will still be hard to get the complete state in the final step.
- What we can do instead is lifting the state up, as you've already pointed out :-)
https://codesandbox.io/s/wizard-custom-abstraction-forked-9bm1f
In this example, I'm storing the state inside of the Custom Wizard Component and pass a helper to set and read the state for a form field via context.
But you can do this basically any way you want. If your form is fairly complex you might consider a form library like Formik that works in perfect harmony with react-wizard-primitive :-)
Let me know if you need help setting this up, I'm happy to help :-)
from react-wizard-primitive.
Thank you very much for your thorough response and also the provided examples. I am sure that they will guide other people who are researching similar questions in the future.
Unfortunately I was already under a little time pressure. Therefore I searched for other possible solutions and finally decided to use this package https://www.npmjs.com/package/react-step-wizard. It is also rather unopinionated but has the advantage (if you consider it an advantage) that the components are not unmounted and I don't have to personally care about unmounting/mounting them.
The reason being is that I have some rather complex controlled components (not just simple forms) as my wizard steps and it would have been a lot of work (and maybe cause performance issues) to rework them so that the wizard completely manages their state.
Thank you anyway. You answered my question. I'll just leave this issue open in case you want to add anything more.
from react-wizard-primitive.
Sure :-) Glad you found a solution that works for you.
All the best! :-)
from react-wizard-primitive.
Related Issues (20)
- Add visited flag to step
- add examples
- issue with nested components
- add routing
- Expose useWizard API in Wizard Component as render props
- hasBeenActive should be false to the first element HOT 1
- add contributors
- New prop initialStepIndex HOT 4
- Fix readme shield links
- Add onChange handler HOT 1
- Add option to skip onChange handler when calling goToStep HOT 2
- Disabled routing HOT 12
- uzeWizardStep causes steps to not render HOT 1
- Exposes maxStepIndex to useWizard
- README.md small improvements HOT 2
- Step won't render when coming back from another route HOT 2
- Using <React.StrictMode> doesn't render the step component HOT 3
- Prevent render flicker when using routeTitle
- add moveToStep and resetToStep to useWizard API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-wizard-primitive.