setQueryData fails silently during an optimistic mutation #4799
Unanswered
danielreuter
asked this question in
Q&A
Replies: 2 comments
-
wouldn't know why this shouldn't work. can you reproduce this in a sandbox please? |
Beta Was this translation helpful? Give feedback.
0 replies
-
@TkDodo the problem was that I imported the QueryClientProvider from @tanstack/react-query and then the useMutation from react-query -- not sure if there's a way to prevent people in the future from doing this... Thanks anyway. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using
useMutation
to optimistically update an upvote/downvote component that renders data from auseInfiniteQuery
--the client needs to see the buttons change in the browser instantaneously.But
setQueryData
fails to alter the cache. Below is code taken straight from the docs for an optimistic update, where I've simply added the use ofimmer
(though it fails when usingmap
as well) and typed the cache data appropriately. It produces no change in the cache:The only way I've gotten this to work is to mutate the cache directly (I don't want to push this to production obviously):
If I were to guess what the problem is, I'd say that there is some detail in the implementation of
setQueryData
that makes it fail if its argument doesn't have the right type, and that I've somehow typed the input data incorrectly -- but that seems falsified by the fact that the direct mutation works.Any ideas? Very much appreciated--thank you.
Beta Was this translation helpful? Give feedback.
All reactions