r/reactjs • u/KaleRemarkable1019 • Aug 04 '26
Show /r/reactjs Everyone says Context is bad for shared state. Does it have to be?
The usual advice: Context is fine for theme and auth, not for state that changes often. True — but the reasons are specific, not fundamental:
- No selectors — any change re-renders every subscriber.
- If the provider also holds the state, its whole subtree re-renders, even components that never read the context.
- Actions get a new identity on every keystroke.
All three are fixable. I've made a library that tackles them, and the article ends with it.
Where do you think this is wrong? Especially the "just use zustand/jotai" case.
0
Upvotes
9
u/friendshrimp Aug 04 '26
Typical Ai slop writing style
8
u/hyrumwhite Aug 04 '26
I’d rather use a big, well tested and popular library that solves this while simplifying usage, like zustand
5
u/Honey-Entire Aug 04 '26
Frankly this doesn’t seem like a reason to add another dependency to a project and add one more attack vector for someone trying to get malicious code onto my computer.
All of the problems you present are patterns for React best practices and can fairly easily be avoided, like you showed in your blog post…
2
u/MitchEff Aug 04 '26
There are so many libraries that fix exactly all of that. react-tracked is a particularly handy one (or zustand/valtio if that's your flavour)
2
u/arnorhs Aug 04 '26
Who is this everyone. Context has gotchas and it doesn't work for all use cases, but great for others. Don't drink every coolaid
1
u/Savalava Aug 04 '26
what is advantage of your libary over just using normal react context and React.memo?
1
u/m-fasciano Aug 05 '26
I think people often oversimplify it.
The problem isn't Context itself, it's how it's used. If everything is stuffed into a single provider with values changing all the time, then yes, you'll get unnecessary re-renders. But if you split contexts by concern, keep values stable, and avoid recreating functions on every render, Context can scale much further than people give it credit for.
That said, libraries like Zustand and Jotai solve these problems out of the box and usually provide a nicer developer experience. I'd only reach for them once the app genuinely needs the extra flexibility, not by default.
I'll definitely give the article a read. I'm curious to see how your library handles selectors and keeps updates isolated.
1
u/SecureComfortable259 Aug 06 '26
The "just use zustand/jotai" pushback usually isn't really about whether Context's limitations are fixable, it's that those libraries already solved this years ago and are one dependency away, so the question becomes what a new library buys you over just using something with a bigger community and more battle testing. Worth leading with that comparison directly since that's the actual objection people are going to raise.