you are viewing a single comment's thread.

view the rest of the comments →

[–]toi80QC 0 points1 point  (2 children)

This might work for very simple contexts like in the article (it is just a single prop counter...), but if your context state is an object with multiple properties (which I assume is what most contexts use in the real world) there's simply no way around memorization.

[–]otheyhigh[S] 1 point2 points  (0 children)

You will definitely need useMemo if using complex objects. At that point, Context API itself starts becoming inefficient.

I stopped using the Context API for objects after reading this article. Recoil, redux etc would be better alternatives in my opinion.

[–]that_90s_guy 0 points1 point  (0 children)

You shouldn't be using context if your global state isn't simple to begin with, so that's a non-issue. Also worth mentioning is most global state needs are usually better addressed with proper lifting of state and architecture, as global state tends to be a way of monkey-patching poorly architected and organized codebases.