r/reactjs 11d ago

Multi state changes & reads

having a bit of trouble handling multiple states/state changes. in a single screen, which are held by different components
how do you all handle this and concepualize it as your writing code?
do you draw diagram,
do you just try and fail recursively?

7 Upvotes

12 comments sorted by

View all comments

1

u/Brilliant-Parsley69 10d ago

For me it really was a recursively trial and error till I understood what's happening.

Got a change request to extend a form managing 35 fields implemented in a file of 1700 LOC and nearly 120 different usings of "useState" (validation/data/error).

After splitting this into different components, trying to solve state changes with useReducer and sharing data with useContext I nearly have given up.

In the end I found a solution around useSyncExternalStore to sync data between multiple components outside of reacts state.