Skip to content

Cache results from select #8310

Answered by TkDodo
toppsdown asked this question in Q&A
Nov 19, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

outside caching is your friend, e.g. with reselect or memoize-one:

const cachedSelector = createSelector(
 data => data,
 data => calcWeek(data)
)
useQuery({
  queryKey,
  queryFn,
  select: cachedSelector
})

now, select is cached per input, even across usages. Keep in mind that most cache libs only keep the latest version, so if data changes frequently between components, this caching achieves nothing.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@peterpme
Comment options

Answer selected by toppsdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants