Skip to content

Refetch after mutation with different parameters #5449

Answered by TkDodo
JoakimGit asked this question in Q&A
Discussion options

You must be logged in to vote

yeah, this is a surprisingly tricky one. The API seems a bit weird, but I guess it's out of the question to change it. My thinking is that usually, the client shouldn't care about such things. The mutation itself should probably fill the cache on the server - it's not the client's responsibilities to instruct the server when to use a server-side cache and when not.

I think storing that value somewhere else (zustand sounds fine) and then reading it in the queryFn in a non-reactive-way seems like the best approach. With non-reactive, I mean do not have a const fromCache = useStore(store => store.fromCache) outside the queryFn and then close over it, because you will run into stale closure p…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@JoakimGit
Comment options

@TkDodo
Comment options

@anpave10
Comment options

Answer selected by JoakimGit
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