React Query

Concepts

Ensuring Not Receiving Stale Data

This can be useful if you’re initially populating a form object from the data, so a rerender later won’t update it.

The most reliable way is to call queryClient.removeQueries() so the data is not present at all.

QueryClient Options

new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: false,
      retry: false,
      staleTime: 5000,
    },
  },
});

Troubleshooting

Queries running when enabled is not true

Check to see if it’s undefined; RQ will run the query when it’s undefined. Safest to make totally sure it’s actually true or false - https://github.com/TanStack/query/issues/1196#issuecomment-2043328137