isLoading
isn't safe to use in a hook's dependency array because it comes from a mutable object, not state
#4519
Replies: 4 comments 3 replies
-
Looking into this further, I see that this CodeSandbox repro I put together actually has a lint warning from the
Emphasis mine. In the case where React bails on the state update, the render is not completed. Unfortunately, the eslint warning pictured below will not appear for |
Beta Was this translation helpful? Give feedback.
-
Just going to continue talking to myself here :) I see that in RQ3, the |
Beta Was this translation helpful? Give feedback.
-
isLoading comes from an external store, and we use
mutations don't have that property, yes. They also very likely don't need it.
refs are mutable objects from react, this is totally different to how our store works. |
Beta Was this translation helpful? Give feedback.
-
I think this whole thread comes down to discussing this point (the rest was me finding my way through the docs & implementation details!). In my app, we've got a Submit button that we want to disable while a mutation is in flight. In order to correctly update this UI, it seems that we need to create our own |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In React Query v2.5.6 (and likely all of v2),
isLoading
was actual component state. This appears to have changed in v3, and it continues to not be React component state in v4 as well. This is true for bothuseQuery
anduseMutation
.I was surprised to see when upgrading that some of our
useEffect
hooks that had[isLoading]
in the dependency array were not always executing even when that value changed. This led me to this explanation from Dan Abramov, where he states that essentially anything that is not a prop or state isn't guaranteed to ensure that auseEffect
hook fires because React could bail on the update. I'd argue that this is a major gap in React's documentation, and it requires developers to know the implementation details of every value they put into a dependency array, which strikes me as unreasonably burdensome.Curious to know the maintainers' and community's thoughts on this.
Beta Was this translation helpful? Give feedback.
All reactions