Type safe way to access queryData using queryKey.
Right now if i want to access query data, i will do something like this
queryClient.getQueryData(['GetCountries', { code: 'BR' }])
But 'GetCountries' part is something which is not autosuggested, it is a string value, which can lead to potenial errors.
Do we have something like getQueryKey to get key for a query.
Thanks
2 Replies
stormy-gold•3y ago
please read: https://tkdodo.eu/blog/effective-react-query-keys
Effective React Query Keys
Learn how to structure React Query Keys effectively as your App grows
rare-sapphireOP•3y ago
I solved it by using
queryClient.getQueryData(
useGetCountriesQuery.getKey({
code: 'BR',
})
);
getKey method is exposed for each generated request.