You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that the selectFromResult callback in useQuery seems to be running any time any data in the store changes.
I'm trying to understand if this behavior is necessary.
Expected Behavior
I'd prefer selectFromResult to only run when the relevant data changes (on changes to loading state or the response data).
Benefit
The primary benefit of improving this behavior is that if someone (intentionally or accidentally) returns an unstable response from selectFromResult, the component will only re-render twice for every request that gets made (isLoading is set to true then false).
Reproduction
I have a simple sandbox that illustrates this behavior here.
I intentionally return an unstable reference in selectFromResult for useQuery B to show how many times selectFromResult is running. (The code sandbox was not reliably emitting console logs.)
I wasn't clever enough to figure out a way to fix it myself, but my hope is that the selectFromResult selector can be modified to only run when the relevant store data changes.
Note
I noticed there are a couple of existing issues that may be relevant to the discussion:
Problem
I've noticed that the
selectFromResult
callback inuseQuery
seems to be running any time any data in the store changes.I'm trying to understand if this behavior is necessary.
Expected Behavior
I'd prefer
selectFromResult
to only run when the relevant data changes (on changes to loading state or the response data).Benefit
The primary benefit of improving this behavior is that if someone (intentionally or accidentally) returns an unstable response from
selectFromResult
, the component will only re-render twice for every request that gets made (isLoading
is set totrue
thenfalse
).Reproduction
I have a simple sandbox that illustrates this behavior here.
I intentionally return an unstable reference in
selectFromResult
foruseQuery B
to show how many timesselectFromResult
is running. (The code sandbox was not reliably emitting console logs.)How to fix
The implementation of
selectFromResult
is here.I wasn't clever enough to figure out a way to fix it myself, but my hope is that the
selectFromResult
selector can be modified to only run when the relevant store data changes.Note
I noticed there are a couple of existing issues that may be relevant to the discussion:
I created a separate issue because I'm specifically looking to understand why this behavior is happening and whether it's possible to improve it.
The text was updated successfully, but these errors were encountered: