State Management · Senior · Question 29 of 75

What does the select option of useQuery give you?

const count = useQuery({ queryKey: ["todos"], queryFn, select: (d) => d.length });

Explanation

The cache keeps the full response while each component subscribes to its own projection. Keep the select function stable (define it outside or memoize it) so it isn't re-run on every render.

Further reading

Problem with a question

State Management · Senior · question 29

Test yourself

Take the State Management · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz