Skip to content
Discussion options

You must be logged in to vote

I don't think that you should be using the queryClient as a "local" state manager. if you are using background updates or other forms of re-fetches, your data will be overwritten by the server state.

the idea is that you and the queryClient don't own the state - it's just a view of what is on the server, which is as up-to-date as you like it / make it. The only way I am ever writing to the query cache is:

  • for optimistic updates
  • to write data back to the cache after a mutation instead of invalidating

I would suggest that you keep the "edits" that the user makes separate from the queryClient. Can be in local react state, or another state manager like zustand or even redux.

Your local data…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by hoetmaaiers
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@TkDodo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants