Component rerender when query changes from fresh to stale? #4929
-
Assume the API data can be fetched, This will cause the three logs, (i.e. component render?)
I'm a code newbie and just learning React, much appreciate for answering this fundamental question🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In your example, you aren't using anything of the query - In a normal situation, you'd do:
now, you've "used" |
Beta Was this translation helpful? Give feedback.
useQuery
returns a bunch of different options, one beingisStale
. This will transition fromfalse
totrue
after 5 seconds. However, react-query is highly render optimized. In v4, we hadnotifyOnChangeProps: 'tracked'
, which became the default in v4. It means that usually, it will only re-render if a property that you are using in the component changes.In your example, you aren't using anything of the query -
result
is ignored. Since you're not using an properties, we're observing all of them, so you'll get that re-render.In a normal situation, you'd do:
now, you've "used"
data
, so we…