When does useQuery hook triggers re-render ? #2267
-
I have a use case where I select some data object from the remote data fetched. For example below: const {data} = useQuery(
['_key'],
dataFetcher,
{
// select a data object from a parent object
select: (dataFetched) => {
const meta= dataFetched.someProjects;
return meta[ID];
},
} Now here I am selecting an object from the whole data fetched. My question is, will react-query trigger rerender if anything in the whole data object changes except the data used in query ? Also it will be really helpful if you can point me to some docs where I can read how re-renders are triggered when data changes. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
the subscription is based on the result of the select function. I have a blog post on re-renderings here: https://tkdodo.eu/blog/react-query-render-optimizations generally, I wouldn't worry too much about re-renders. let it render if it needs to render until you find a perf problem with it :) |
Beta Was this translation helpful? Give feedback.
the subscription is based on the result of the select function. I have a blog post on re-renderings here: https://tkdodo.eu/blog/react-query-render-optimizations
generally, I wouldn't worry too much about re-renders. let it render if it needs to render until you find a perf problem with it :)