TanStackT
TanStack14mo ago
3 replies
broad-emerald

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
Was this page helpful?