Skip to content
Discussion options

You must be logged in to vote

So selectors generally run on every render, because most of the time, they are very inexpensive. Technically, they always run if the functional reference changes or if the input (request data) changes. To improve this, you an memoize the selector function, either by extracting it to have it outside of the component, or with useCallback if it has dependencies.

You can read more about that in my blog here: https://tkdodo.eu/blog/react-query-data-transformations#3-using-the-select-option

I'd also happily accept a PR to the docs that somehow mentions this behaviour, on some page where it fits :)

Replies: 2 comments 2 replies

Comment options

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

You must be logged in to vote
2 replies
@seanforyou23
Comment options

@TkDodo
Comment options

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