DEV Community

Discussion on: The state of React's state management for me

Collapse
 
marcelltoth profile image
Marcell Toth

While a great exercise, this is horrible for performance unfortunately and will not scale.
One of the hardest parts about React state management is managing re-renders.

A component in well written redux (or mobx or whatever, for that matter) app will only re-render if the parts of state it uses have changed. In redux this is achieved by writing good selectors, in mobx it is the automatic proxy that does that, which is the main selling point of the library.

In your example every component that uses AppContext will re-render each time every single thing changes. This is not scalable, and that's where libraries still come into play.

Collapse
 
ivan_jrmc profile image
Ivan Jeremic • Edited

That is true if you use it wrong, but if you use context correctly it works fine at large scale and I would anyway never put server state in Redux that's why I use for server data ReactQuery and for client state context + useReducer, Redux is horrible when used for server data.

Collapse
 
akumzy profile image
Akuma Isaac Akuma • Edited

While what you said might be totally correct, you should not put a component level state in your global state
Whatever state field I have in my global store I am expecting it to affect my entire app so I don't think that's much of a big deal