T
TanStack9mo ago
wee-sapphire

Persisting Data with Query

Nested within _authed, I have several different routes and trees relying on profile ID. I'm looking for the best practice to store the ID. I originally started with Zustand for this but trying to utilize React Query for this as much as possible, but getting confused on integrating that with routers. Currently, I store the session info in router context and was looking to do the same with profile ID (after fetching with session.user.id) but not sure the best way to use that and fetch profile data for nested components. There is also a workflow for a user to view a separate profile so the profile ID would need to be changed on the fly. Is context the best approach? Do I need to worry about reloading the page and unnecessary re-fetching of the ID? Any advice on best practice and an example would be much appreciated! I'm getting confused with using context vs datastores and incorporating Query
2 Replies
deep-jade
deep-jade9mo ago
query would also forget its cache (unless you persist it manually) upon reload maybe explain first what you mean by "reloading the page"
wee-sapphire
wee-sapphireOP9mo ago
Maybe I'm thinking about it wrong, but If context is set in a parent route, would it get reset on any child route or only on parent route rerender?

Did you find this page helpful?