DEV Community

Discussion on: Context in React

Collapse
peerreynders profile image
peerreynders

sebmarkbage 2018

My personal summary is that new context is ready to be used for low frequency unlikely updates (like locale/theme). It's also good to use it in the same way as old context was used. I.e. for static values and then propagate updates through subscriptions. It's not ready to be used as a replacement for all Flux-like state propagation.

Granted the example shown here deals with "locale/theme" data — the issue is that it would be all too easy to get the impression that it is OK to store "regular data" within context.

For example Redux and MobX simply store an access point that never changes during the entire application session within context.

That (never changing) access point makes it possible to subscribe to updates from the library runtime. Once the subscribed, context is rarely involved in component ⬌ data exchanges.

Collapse
sahilkoun profile image
Sahil Author

I am Sorry, I should have mentioned about the things me might store in Context (like which changes not on regular basis) and the things we might not.

Collapse
peerreynders profile image
peerreynders • Edited on

No need to apologize — for the most part the official docs are silent on the matter and I only became aware of it through Mark Erikson's Why React Context is Not a "State Management" Tool.

Phrased differently: Context is a place for "first introductions" between components and cross-component state (management) but not for "regular meetings" between them.

In my opinion the countless "don't need Redux, just use Context" statements communicate a misunderstanding of what context actually is.

There are "lighter" (cross-component) state management solutions like unistore, valtio, zustand and jotai.