V5 queryClient.getQueryData argument is changed to accept only a queryKey #6166
Answered
by
TkDodo
joel-daros
asked this question in
Q&A
-
We're trying to migrate to V5, but this breaking change is preventing us. I have the following code: const selectedParameter = "123"; // this values comes from the query params
// this is the partial name of the query. The complete query key is a huge and complex key based on multiple dynamic parameters
// it’s impossible to retrieve the complete query key at this point of the code.
const queryKey = ["foo", selectedParameter];
// get data from the current react query cached data
const pivotResponse = queryClient.getQueryData(queryKey, {
exact: false,
type: "active",
}); Is there any alternative to request an active cached data without know the complete query key in V5? |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Oct 17, 2023
Replies: 1 comment 4 replies
-
but this approach is quite brittle: if you have multiple active queries, you'll get a "random" one. Also, where do you need It's best practice to make all parameters that you need to make a query available to all places that need them. This is a "client state management" problem |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
joel-daros
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
but this approach is quite brittle: if you have multiple active queries, you'll get a "random" one. Also, where do you need
getQueryData
if not for optimistic updates?It's best practice to make all parameters that you need to make a query available to all places that need them. This is a "client state management" problem