-
I'm working with an API where the team mandates we bulk fetch items, instead of multiple parallel requests for single items. On the first page of the app that displays all items I create a query for the bulk fetch: const postIds = ["abc1", "def2", "ghi3"];
const { data } = useQuery({
queryKey: ["posts", postIds],
queryFn: async () => {
return await axios.get("/posts", { query: { postIds } });
},
}); On an individual item page, I'm creating a query for the individual item: const postId = ["abc1"];
const { data } = useQuery({
queryKey: ["posts", postId],
queryFn: async () => {
return await axios.get(`/posts/${postId}`);
},
}); This individual post of course doesn't match the cache because the keys are different from the previous bulk fetch so triggers a request for the item, but I already had the data from the previous page - the request isn't necessary. What is the best way to go about this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
you need something like data-loader to achieve that. This is a good discussion with a reproduction: |
Beta Was this translation helpful? Give feedback.
you need something like data-loader to achieve that. This is a good discussion with a reproduction:
#365 (comment)