TanStackT
TanStack2mo ago
42 replies
uncertain-scarlet

Dynamic form removing fields when rerendering

Hi all,

I'm trying to create a form where different answers show up based on what options the user has already selected in the form. So I need to calculate which sections are in my form dynamically from the current state of the form. So I'm trying to watch for changes to the form state, recalculate the sections, then I'm just using a For control in SolidJS to render out whatever sections.

However when the form redraws, it removes the fields from the form and their values. And at best then when it redraws it's just removed all the values from my form. Or worst case, it creates an infinite loop because it'll run a redraw each time a field is added/removed, so just gets stuck in a loop.

Is there a better way to handle dynamic forms? I'm not sure how to get around this issue tbh
Was this page helpful?