Skip to content
Discussion options

You must be logged in to vote

Because a large number of select usages are now anonymous arrow functions, resulting in repeated execution of select at each render, the default behavior has too much unnecessary performance loss.

I disagree that it is a performance loss. Consider:

const useTodoById = (id) =>
 useQuery({
    queryKey: ['todos'],
    queryFn: fetchTodoObject,
    select: data => data[id]
  })

this select transformation is a simple object pick. It's fine to run on every render. So as always, "it depends". Adding useCallback here would likely make things slower, because you would need to memoize and cache a trivial object lookup.

Comparing to other state managers that have selectors like zustand or redux,…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by shijistar
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants