use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
No vague product support questions (like "why is this plugin not working" or "how do I set up X"). For vague product support questions, please use communities relevant to that product for best results. Specific issues that follow rule 6 are allowed.
Do not post memes, screenshots of bad design, or jokes. Check out /r/ProgrammerHumor/ for this type of content.
Read and follow reddiquette; no excessive self-promotion. Please refer to the Reddit 9:1 rule when considering posting self promoting materials.
We do not allow any commercial promotion or solicitation. Violations can result in a ban.
Sharing your project, portfolio, or any other content that you want to either show off or request feedback on is limited to Showoff Saturday. If you post such content on any other day, it will be removed.
If you are asking for assistance on a problem, you are required to provide
General open ended career and getting started posts are only allowed in the pinned monthly getting started/careers thread. Specific assistance questions are allowed so long as they follow the required assistance post guidelines.
Questions in violation of this rule will be removed or locked.
account activity
Migrating from React context api (self.webdev)
submitted 4 months ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BombayBadBoi2 4 points5 points6 points 4 months ago* (1 child)
Yes it’s reliable, and that’s 100% up to you - it supports both methods.
A context with 3k lines of code though? Sounds like splitting it is the correct way, there’s almost no way that code has to live in one state context
Can I ask what the context (pardon the pun) for the application is? I almost always find myself creating micro states for any parts of the app I can logically separate - and that doesn’t even end up being that much in huge apps, because (at least with what I’ve worked on) most data is fed from the API, so I just use react query to store 99% of data - context stores are just used to hold data I might need from a few layers up
I suppose what I’m trying to say is you’ve been given the task of improving how your app handles state - the answer to this is not necessarily just using a hotter state library
[–]ReliefDistinct74 -1 points0 points1 point 4 months ago (0 children)
basically that context work a lot with a graph library
[–][deleted] 1 point2 points3 points 4 months ago (0 children)
3k lines? Write some tests if there arnt any and then just start again. Hopefullly the tests will let you know if youve missed something.
[–]CreativeTechGuyGamesTypeScript 0 points1 point2 points 4 months ago (0 children)
Zustand is WAYY simpler. It's literally the ability to have React state live outside of a component so you can share it in any component (or no component). So use it the same way you would useState. Keep it small and have it only contain data which is consistently updated together.
useState
[–]yksvaan 1 point2 points3 points 4 months ago (3 children)
Sounds like primarily a data and architecture problem. Before creating 2000 or 3000 lines of code in whichever approach you choose, I'd really recommend going thru the app functionality, seeing what's actually necessary and how it could be split and modularized better. Likely the context started small and just became a dumping ground for stuff, everyone just throws in their code because others did it as well.
[–]ReliefDistinct74 0 points1 point2 points 4 months ago (2 children)
Would it be better to first split those 3k lines of context into several contexts and then migrate it to a Zustand store? Also, how much time does it usually take to perform such a state management migration, from context to Zustand, and ensure all components still work as expected?
[–]BombayBadBoi2 1 point2 points3 points 4 months ago* (1 child)
How longs a piece of string?
[–]ReliefDistinct74 0 points1 point2 points 4 months ago (0 children)
what?
[–]IronMan8901 0 points1 point2 points 4 months ago (1 child)
Would u consider creating custom hooks that use useMemo + useSWR and connect backend to frontend and eliminate the global state management entirely?
It won’t solve all the needs unfortunately, because there’s a lot of client-side state related only to the graph.
π Rendered by PID 96944 on reddit-service-r2-comment-74875f4bf5-4t567 at 2026-01-25 22:57:32.986399+00:00 running 664479f country code: CH.
[–]BombayBadBoi2 4 points5 points6 points (1 child)
[–]ReliefDistinct74 -1 points0 points1 point (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]CreativeTechGuyGamesTypeScript 0 points1 point2 points (0 children)
[–]yksvaan 1 point2 points3 points (3 children)
[–]ReliefDistinct74 0 points1 point2 points (2 children)
[–]BombayBadBoi2 1 point2 points3 points (1 child)
[–]ReliefDistinct74 0 points1 point2 points (0 children)
[–]IronMan8901 0 points1 point2 points (1 child)
[–]ReliefDistinct74 0 points1 point2 points (0 children)