different query key for queries and mutations #2521
Replies: 2 comments 2 replies
-
why are you doing that? I don't think that's what this function is for. It is usually just for making sure that the queryKey is serializable. You can't expect to be able to access elements with the result of the hashQueryKey function. the result is always a string, but the input can be an array with objects as well. so the query key you pass to getQueryData / setQueryData should always be the queryKey before being processed by the queryKeyHashFn. |
Beta Was this translation helpful? Give feedback.
-
hi, @TkDodo can a mutation and query have the same key without issue? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I wan to reuse the query key to get data from the server and modify that query after mutation, but I am seeing different query keys to the same query
Query key on the left panel:
["/speedups/appdetails_appManager",{"customer_id":"55-6718-A000","frequency":30,"level":"appManager"}]
Query key on the right panel
the first item of the array is
"/speedups/appdetails",
but on the left panel is/speedups/appdetails_appManager
Problem 1 with getQueryData
Now, when I try to get cached data using
queryClient.getQueryData
using the query key on the left panel, it doesnt work, I need to use the query key from the right panel.It doesnt work:
It works:
Problem 2 with setQueryData
Now, the opposite happens here, when I try to update cached data using
queryClient.setQueryData
using the query key on the right panel, it doesnt work, I need to use the query key from the left panel.It works:
It doesnt work:
NOTE:
I am using the property: queryKeyHashFn to add the text appManager and modify the query key but Im seeing this behavior.
Beta Was this translation helpful? Give feedback.
All reactions