Replies: 1 comment 1 reply
-
I was with you up to this point, but then you lost me. If you have a query with this key:
in the cache, and you update the data in the cache after a mutation for this exact key, why would it then re-fetch...? |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Would someone advice me what is correct approach to update a data with useMutation when useQuery has parameters?
Lets assume we have this code:
So the method methodWhichTakesThoseIds takes
["id1", "id2"]
and returns some data from database. This data is an array of objects type like SomeModel[]. For eg. it could be:[{name: "foo"}, {name:"bar"}]
All good, but now I want to update this data on screen and on database with useMutation
So now I added new item to database and the data in case should be:
[{name: "foo"}, {name:"bar"}, {name:"newOne"]
.All good again, but when I change the route and back again, the useQuery with only 2 IDs will fire again and useQuery returns data with only two element from database because it has only two IDs as paramters
["id1", "id2"]
.If I'll set
I'm still using original useQuery with only two IDs so changes won't reflect on screen.
I guess there are solutions like refetch data from server every time after update, but main question is"
What is the best approach to update data when useQuery has parameters - not only the key like
useQuery("key", method)
?Beta Was this translation helpful? Give feedback.
All reactions