In my NextJS app, user has an opportunity to view the list and to add data there.
When user adds the item to the list, its query is invalidated with queryClient.invalidateQueries({ queryKey: ['branchList'] });
.
However, when user navigates back to the list page, the query does not refetch data and user gets the obsolete list.
I've read similar issues on StackOverflow (like this one) and can confirm I use new QueryClient
only once in the _app file:
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
retry: 1,
staleTime: Number.POSITIVE_INFINITY,
},
},
});
export default function App({ Component, pageProps }: AppProps) {
return (
<QueryClientProvider client={queryClient}>
<Layout>
<Component {...pageProps} />
</Layout>
</QueryClientProvider>
);
}
The query itself looks like this:
const { data, isLoading, error } = useQuery({
queryKey: ['branchList'],
queryFn: getAllBranches,
});
Also, I can see in console that the query is invalid:
I would really appreciate any help with this issue. Thanks in advance!