redux-toolkit
redux-toolkit copied to clipboard
Am I missunderstanding RTK Query Cache feature?
When I make a request in Lazy Query, I cache the returned result and try to use the data in the cache even if the page changes. I make a request, the result is returned, and when I change the page, it appears as data: undefined, even though I set the preferCacheValu to true. What am I doing wrong? My code is given below;
const [
getCachedStockDocumentList,
{ data: stockDocumentListData}
] = mrpApi.endpoints.getApiStockDocumentStockDocumentList.useLazyQuery();
console.log(stockDocumentListData)
//request
onClick={async () => await getCachedStockDocumentList({}, true)}
It took me some time to understand, but I believe you should call the hook directly in the other component or pass it as a prop.
const { data, error, isLoading } = useMrpApiQuery()
In this case, it will theoretically recover directly from the cache without making a new request. Adding { skip: false } will prevent the automatic request. Theoretically I believe that it makes more sense to create a state to turn skip on and off. Which in your case makes more sense.
https://redux-toolkit.js.org/rtk-query/usage/conditional-fetching
It took me some time to understand, but I believe you should call the hook directly in the other component or pass it as a prop.
const { data, error, isLoading } = useMrpApiQuery()In this case, it will theoretically recover directly from the cache without making a new request. Adding { skip: false } will prevent the automatic request. Theoretically I believe that it makes more sense to create a state to turn skip on and off. Which in your case makes more sense.
https://redux-toolkit.js.org/rtk-query/usage/conditional-fetching
in my page that request not fetching automaticlly. I'm using button for fetching, when I press that button I call that request and when request response success I need the cached response, so when I change page and comeback I can see cached data but it's not, it is undefined and what I wonder am I understand wrong cache feature or is this way wrong?
Hi I am also curious about this. I lazy fetch and navigating away and back then results in status uninitialized and data as undefined. I expect it to behave similar to the standard query in terms of using the cache.