Skip to content
Discussion options

You must be logged in to vote

useQuery returns a bunch of different options, one being isStale. This will transition from false to true after 5 seconds. However, react-query is highly render optimized. In v4, we had notifyOnChangeProps: '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:

const result = useQuery(queryKey, queryFn, {staleTime: 5 * 1000});
return <div>App {result.data}</div>;

now, you've "used" data, so we…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sam-ckchan
Comment options

@TkDodo
Comment options

Answer selected by sam-ckchan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants