T
TanStack3y ago
rare-sapphire

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
stormy-gold3y ago
Effective React Query Keys
Learn how to structure React Query Keys effectively as your App grows
rare-sapphire
rare-sapphireOP3y ago
I solved it by using queryClient.getQueryData( useGetCountriesQuery.getKey({ code: 'BR', }) ); getKey method is exposed for each generated request.

Did you find this page helpful?