React · Middle · Question 50 of 75
Why does useQuery have a select option?
- ✓Correct answer: To get part of the data and subscribe only to it
- 2To choose which of several queries to run
- 3To list the fields requested from a GraphQL server
Explanation
useQuery({ queryKey: ['todos'], queryFn, select: d => d.length }) - the cache stores the full response, while the component gets a derived value and subscribes only to it. For a stable reference, move the select function outside the component or memoize it.