1

I am using React query on a React app that makes multiple paralell requests. Every time I hit tab to go to another app or page, it removes all the dashboards and shows spinner. It refetches all the data and makes all the requests again even when the keyword in the search bar has not changed and, therefore, it is not useful to make the user wait for another few seconds to be able to see the dashboards.

3
  • Per default, react query always shows stale data if there is any and does background refetches at the same time. So please show some code because it must be something like always showing a spinner when isFetching is true or so Commented May 6, 2021 at 19:22
  • ``` ) : isLoading || isFetching ? ( <BounceLoader size={60} color={'#fdcf85'} css={override} /> ) : isError ? ( <span>Error: {error.message}</span> ) : ( <> <div className='m-4 p-4 flex w-full overflow-x-auto justify-center items-center bg-amethyst border-collapse'> <Table columns={tableData} data={formatData(data)} /> </div> ``` Should I get rid of isFetching and only keep isLoading? Commented May 7, 2021 at 6:57
  • Well if you unmount all the data and show a loading spinner every time a request is in-flight, which is what isFetching is doing, and you don’t want that, then yes, I’d suggest to remove that :) Commented May 7, 2021 at 9:19

1 Answer 1

4

disabling refetch on focus might help you, but I would remove isFetching at all and left only isLoading

const queryClient = new QueryClient({
   defaultOptions: {
     queries: {
       refetchOnWindowFocus: false,
     },
   },
 })

source: https://react-query.tanstack.com/guides/window-focus-refetching

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.