Select + setQueryData interaction #3430
Replies: 2 comments 3 replies
-
From your comment, I would guess that you have tried immutable updates already, but it is still the most likely case of error. Note that if you only create a shallow new object, but then mutate
Immutability is required when working in react. If that is too cumbersome, have look at libraries like immer |
Beta Was this translation helpful? Give feedback.
-
It seems that when using select, the library must be doing something other than simply caching the most recent value (set during the last render) and equality comparing it against the new value to decide if a re-render should take place. React-query must either traverse all the way up the object, checking for referential integrity at each step in order to determine a change, or it's not caching the last value at time of render and instead simply looking at the current value in the cache and comparing it to the new data. Perhaps this decision has something to do with the 'structural sharing' design? It's a shame to be forced down the immutable path if wanting to use select + optimistic updates, considering the rest of the framework appears to work fine with mutable objects. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm testing out react-query for a project and am confused about the interaction between optimistic updates and select.
From my testing, if I have a main query, like so
And then do an optimistic update, eg from a successful mutation
And have another query, like the following, in another part of the application. It does not get triggered for re-render by setQueryData
I am only able to get the ability for 'select' to reduce re-renders when a refetch() is called. select is completely ignoring manually triggered updates called by setQueryData().
Is this by design or am i missing something?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions