Skip to content
Discussion options

You must be logged in to vote

the query keys need to strictly match when calling useQuery. You could manually prime the cache after prefetching and create one entry per id.

Or, with select, you would get a useSelector like api:

const useItemsQuery = (ids, select) => 
useQuery(['items', [ids]], () => fetchFn([ids]), { select })

const useItem = (ids, id) => useItemsQuery(ids, (data) => data.find(item => item.id === id))

but you have to tag around all ids for the query key, and every refetch will still fetch all items

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mzedeler
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