Skip to content

useQuerySelector instead of select option in useQuery #3353

Answered by TkDodo
zaverden asked this question in Ideas
Discussion options

You must be logged in to vote

We've iterated over selectors a lot of times since that comment, and there are currently no plans to remove them for v4. The issues mentioned in #1639 have been fixed. We now run select every time data changes or the referential identity to select itself changes, which might be on every render if it's an inline function (which likely doesn't matter much), but it can be optimized via useCallback or by extracting it to a stable function reference. I've written about that here: React Query Data Transformations.

One very strong argument for the current architecture is partial subscriptions. For example:

function useTodosQuery(select) {
  return useQuery("todos/all", loadTodos, { select });
}
…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@zaverden
Comment options

@Klemminn
Comment options

@TkDodo
Comment options

@Klemminn
Comment options

@gromaco
Comment options

Answer selected by zaverden
You must be logged in to vote
1 reply
@TkDodo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
5 participants