Are dynamic layouts ok to use?
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
I have a multi step form where each step has it's own endpoint to submit the data to backend, so we keep track of the form submitted steps and user can continue later where they left. The form has actually 5 fixed steps so I want to create a dynamic route [step] I wondered if it's ok to put also the layout.tsx inside [step] because for each different step I need to provide the logic whether the button to continue is enabled or disabled, as this button is shared across pages
5 Replies
@Brown bear I have a multi step form where each step has it's own endpoint to submit the data to backend, so we keep track of the form submitted steps and user can continue later where they left. The form has actually 5 fixed steps so I want to create a dynamic route [step] I wondered if it's ok to put also the layout.tsx inside [step] because for each different step I need to provide the logic whether the button to continue is enabled or disabled, as this button is shared across pages
yes, technically you can, but I wouldn't do it. Use clientside components to keep track of your clientside states and whether a button is enabled or not. Use searchParams to load the initial step. That's waaay easier for you in the future and better to maintain
@B33fb0n3 yes, technically you can, but I wouldn't do it. Use clientside components to keep track of your clientside states and whether a button is enabled or not. Use searchParams to load the initial step. That's waaay easier for you in the future and better to maintain
Brown bearOP
if I have a fixed number of steps is it better to create individual pages then instead of having a dynamic page [step], since i need to do validation for each step whether it is allowed or not
instead of multi-step-form > [step] > page.tsx to have
multi-step-form > stepOne > page.tsx
multi-step-form > stepTwo > page.tsx
...
multi-step-form > stepOne > page.tsx
multi-step-form > stepTwo > page.tsx
...
@Brown bear instead of multi-step-form > [step] > page.tsx to have
multi-step-form > stepOne > page.tsx
multi-step-form > stepTwo > page.tsx
...
I would create one Client component that handles the whole multistep form and steh maybe multiple components for each step. Then you have the logic excluded and the steps are indipendet, but can still access the whole form. Validation and saving works fine as well
Brown bearOP
alright gotcha