React query Refetching on page change

let { data: orders, isLoading, isFetching, isError, error, refetch } = trpc.order.getallcart.useQuery(undefined, { retry: 1 });
let { data: orders, isLoading, isFetching, isError, error, refetch } = trpc.order.getallcart.useQuery(undefined, { retry: 1 });
I am using this code ( react query + trpc) , i want whenever i change links , router , the query should rerun and new data should come from the database but it is not happening , i tried various refetching methods but none of them worked , anyone who can suggest something
1 Reply
Kseikyo
Kseikyo10mo ago
what you're probably looking for is query invalidation https://tanstack.com/query/v4/docs/react/guides/query-invalidation you can also use the refetchOnMount: "always" so it will force a refetch on mount even if data is not stale (not marked as invalid)