I'm hoping to leverage XState to be the spine of the logic for a multi-step, onboarding UI. The problems I want XState to solve are:
- Allow me to create this flow in a way where it's extremely simple to reorder steps in the flow.
- Try my best to have a bullet-proof UI via state machine enforcing consistent pattern enforcement.
- Help devs come into an unfamiliar space and have the visual editor to help orient themselves.
The UI is also in a Next.js application and I also want to have each step be a new page file / route.
I see the multi-step form example: https://xstate-catalogue.com/machines/multi-step-form and I found this wonderful example of using React Context providers in Next.js page files to share state globally https://garden.bradwoods.io/notes/javascript/state-management/xstate/global-state - instead of globally, I'd use a layout component, but I think I'm following along.
All that being said, I'm left a bit confused as to how I can code-split the different steps across different page files. One thought I had would be to maintain each step component as a value in a ContextProvider keyed by state names and conditionally render the step based off of the state the machine is in. I can dynamically import each component; however, this strategy wouldn't let me "navigate" between each step via the router since the conditional rendering would happen from one spot.
Maybe I could navigate with path params and have a Next.js dynamic page file conditionally render UI based on the path param; however, this would force me to basically make the flow SSR instead of static on first render and client-side routed afterward.
Would love ideas here!