query icon indicating copy to clipboard operation
query copied to clipboard

refetchOnWindowFocus rerenders

Open vititu opened this issue 6 years ago • 2 comments

I noticed refetchOnWindowFocus fires many rerenders.

There is a sample here: https://codesandbox.io/s/refetchonwindowfocus-test-xxsf5 Notice it will console.log many times on each windowFocus. Is this the expected behavior?

vititu avatar May 03 '20 01:05 vititu

Initially, I thought it has something to do with the iframe focus (As Codesandbox uses it). But I could reproduce the above issue in the app I'm working on too (No Iframes).

The network call is being made only once, but It re-renders 3 times.

thisizkp avatar May 03 '20 02:05 thisizkp

A rerender is triggered for every state change in react query. So mount, fetch start, loading, success, etc. no different than if you were to use useState with useEffect to fetch data.

tannerlinsley avatar May 03 '20 03:05 tannerlinsley