I am using RTK query for data-fetching and I need to clear the cache when the component unmounts. Is that allowed? The problem is, when I open the page, the data is fetched from BE and displayed. The next time when I re-open the same page, the cached data is displayed. But, the changes to the data can be made from another window/computer and the cached data is no longer valid. So, when the page is re-opened, what is being displayed is the old data. So, I did it like this to solve the problem
useQuery(
{
id: pageId!,
},
{
refetchOnMountOrArgChange: true,
},
);
Setting refetchOnMountOrArgChange
to tru
seems to fix the issue. But, I am able to see the cache data for a fraction of second before the new updated data arrives. So, I was thinking to clear the cache when the component unmounts. Or any other solution that can solve this problem, please let me know.