Invalidated Cache but Old Data is Still Getting Pulled #5414
-
Hi guys, I have a weird issue where I'm invalidating cache upon successful mutation, which results in old data getting pulled from cache rather than the new data from the database with the GET request. The Here's what I have. In the index.tsx I have Inside the render function, <ThemeProvider theme={theme}>
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<Parent />
</QueryClientProvider>
</React.StrictMode>
</ThemeProvider>, Outside of the render function const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 50, // Every 50 minutes
},
},
}); In the page component I pull data this way, const { data: formData } = useQuery({
queryKey: ["forms"],
queryFn: () => getFormData(module, space),
}); this is the get function export async function getFormData(module: string, space?: string) {
const { data } = await axios.get(AnomalyDataUrl, {
headers: getAuthHeader(),
params: {
module,
space,
},
});
return data;
} In the component where I mutate the data const queryClient = useQueryClient();
const { mutate } = useMutation({
mutationFn: (form: FormData) => postFormData(form),
onSuccess: () => {
return queryClient.invalidateQueries(["forms"]);
},
}); This is the post function, export async function postFormData(formDara: FormData) {
await axios.post(FormDataUrl, formData, { headers: getAuthHeader() });
} I don't see anything wrong... I've spent more than a day, trying everything I can, researching every single thread related to invalidating queries, but to no avail.. Any help would be greatly appreciated!! Thanks! Using React Query v4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
you need to make |
Beta Was this translation helpful? Give feedback.
that indicates that your browser caches data because of a cache header. As soon as you see the request in the browser devtools network tab, react query "works" and has done its job.