-
As discussed in "React Query Data Transformations", I'd like to use selectors to take different slices from a larger object. If the underlying larger object changes, but the derived/selected data used inside Component X does not, By way of example, say I have a query that returns a
and I have some hooks to take slices of pizza:
If I call So far, so good. But say I want to add logging or something else slightly more complicated to my
The return value is exactly the same as the other
Interestingly, if I do a similar desctructuring in the derived hook, there's no problem:
Try commenting in I'm missing something fundamental here. Can somebody help me understand what's going on? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It appears to be related to tracked-properties.
When you call |
Beta Was this translation helpful? Give feedback.
It appears to be related to tracked-properties.
{...omit(query, 'data')}
looks like it is accessing all properties in the query result under the hood (check_.omit
), which will make react-query think that you need to track all properties, such asdataUpdatedAt
,isFetching
, etc.When you call
queryClient.setQueryData()
, it will also update thedataUpdatedAt
, thus triggering an outer component re-render.