getQueryData(...)
The method enables direct access to the QueryClient
cache to retrieve the data for a specific Query.
See the TanStack queryClient.getQueryData ๐ด documentation.
const data = api.<service>.<operation>.getQueryData(
parameters
);
Argumentsโ
parameters: { path, query, header } | QueryKey | void
- Required parameters to retrieve the data from the Query Cache.
- Instead of an object with
{ path, query, header }
, you can pass aQueryKey
as an array which is also strictly-typed โจ
Returnsโ
The data from the Query Cache for the specific query, strictly-typed โจ
Exampleโ
- Parameters
- QueryKey
const pet = api.pet.getPetById.getQueryData({
path: { petId: 123 },
});
expect(pet?.id).toEqual(123);
const pet = api.pet.getPetById.getQueryData(
[
{ method: 'get', url: '/pet/{petId}', infinite: false, },
{ petId: 123 },
],
{}
);
expect(pet?.id).toEqual(123);