Retrieving query data without passing the whole queryKey
Hi all,
I have a small custom query:
In some components I have no 'params', so I want to retrieve the data like this:
Unfotrunately, I'm getting indefined as a data, because I did not pass the params.
I've found only one dirty trick to fix it - do not pass the 'params' to queryKey array:
const useData = (params?: IParams) => {
return useQuery({
// eslint-disable-next-lone @tanstack/query/exhaustive-deps
queryKey: [queryKey],
queryFn: () => fetchData(params),
enabled: false
})
}
Is that a 'go-to'?
I have a small custom query:
In some components I have no 'params', so I want to retrieve the data like this:
Unfotrunately, I'm getting indefined as a data, because I did not pass the params.
I've found only one dirty trick to fix it - do not pass the 'params' to queryKey array:
const useData = (params?: IParams) => {
return useQuery({
// eslint-disable-next-lone @tanstack/query/exhaustive-deps
queryKey: [queryKey],
queryFn: () => fetchData(params),
enabled: false
})
}
Is that a 'go-to'?