Cache individual but request multiple #158
Answered
by
posva
NikitaVelixJob
asked this question in
Questions
-
Hello! Love this library, I started using it EVERYWHERE. My question is how to make it right. For example I need to get multiple items at the time. const itemsIds = [...];
// get multiple at once
const { data: result } = useQuery({
key: ["items", ...itemsIds],
query: () => getItems(itemsIds),
}); how to make it so it will cache result for each individual key, so later I could do and receive it because we already requested this data? // returns cached because we requested it previously
const { data: result } = useQuery({
key: ["items", itemId],
query: () => getItem(itemsId),
}); Thank you! |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Jan 13, 2025
Replies: 1 comment 9 replies
-
Make the const itemId = ref() // or any reactive value like route.params.id
useQuery({
key: () => ['items', itemId.value]
}) You will find more in https://pinia-colada.esm.dev/guide/queries.html#Reusable-Queries |
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make the
key
a function:You will find more in https://pinia-colada.esm.dev/guide/queries.html#Reusable-Queries