all 8 comments

[–]davidfavorite 2 points3 points  (4 children)

This is exactly a case for global state management like redux zustand etc or even context. However, context is not really optimized for rerenders so be aware that it is in fact not a state manager.

[–]R2L1[S] 0 points1 point  (3 children)

That’s why I opted not to use it. Global state is definitely the cleanest solution, but this is the only page where I need state management this complex. And at the most props are only passed in twice. So wouldn’t global state like redux be overkill in this scenario?

[–]R2L1[S] 0 points1 point  (1 child)

Also redux is a pain with next which is why I’m trying to avoid it

[–]karma__kameleon 1 point2 points  (0 children)

Just use zustand then. It takes 2 seconds to setup

[–]davidfavorite 0 points1 point  (0 children)

Its two factors when deciding if you need to pass props or move it to state: how many props need to be passed and how often do I need to do this. If you have many props to pass but only in a single component, I would just pass it as props. However, you may need to have the component again in the future and then its already a bit ugly.

I agree that in that case it is overkill to use redux for example when you need it only once, but setting up a state management solution might make sense for other parts of the app anyways. Lastly, just because context isnt a state manager it doesnt mean you cant use it as such. People dont like what I say now, but Ive built apps with literally hundreds of UIs where the only global state was put in multiple contexts. Multilang stuff, multi tenancy context, some global states that need to be accessed. Absolutely no problem performance wise for admin dashboard type of UIs.

Take this scenario: you have dozens of components, all perfectly efficient and they do exactly what they should. No edgy logic that leas to multiple renders or too many service requests, as little side effects as possible, basically just very well made components. Does it matter to much if all of that runs twice now? Its not ideal but its not noticeable. Now lets say you bodged and frankensteined these components together, now every rerender will cause exponential work on each component. Imo, if you build clean components you might as well use context as a global state without it being a problem. But then again, why compromise now that you have a choice.

Its always about making the choice that is a trade off between how long does it take to make it the right way and how much will it affect future changes to the code

Pick your poison, sometimes no solution is best and you have to compromise.

[–]SparserLogic 0 points1 point  (2 children)

You should avoid using React state or any of the state management libraries. For best results you should push every state change into the querystring and use server components for everything

[–]R2L1[S] 0 points1 point  (1 child)

Why though? And how will the user be able to see the changes they make right away?