getQueryData is always undefined #420
-
|
Here is a dummy example of my issue. I have a query hook like this: import { listItems } from '../utils/QueryApis';
import { useQuery } from "react-query";
import { ListItemsRequestParams, DataItemTypes } from '../utils/RequestTypes';
export default function useItems(listItemsRequestParams: ListItemsRequestParams) {
return useQuery(['items', listItemsRequestParams], listItems);
}I try to get the cacheData with: function comp() {
const { status, data: items, error, isFetching } = useItems({ query_type });
const test = () => console.log(queryCache.getQueryData('items'))
if (status === "loading") {
return <Loading />
}
if (status === "error") {
<span>Error: {(error as any).message}</span>
}
return <DPButton onClick={() => test()}>Test</DPButton>
}When I click on Test button, it always prints |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
|
I am using version |
Beta Was this translation helpful? Give feedback.
-
|
If I do: console.log((queryCache.getQueries(['items'])[0].state as any).data)I can see the my cached data. |
Beta Was this translation helpful? Give feedback.
-
|
Your query key above is |
Beta Was this translation helpful? Give feedback.
-
|
while doing optimistic update via the cache , If I am doing something like the below
Are there any way to use |
Beta Was this translation helpful? Give feedback.
Your query key above is
['items', listItemsRequestParams], not'items', thus it is returning all queries with theitemsprefix.