T
TanStack10mo ago
rising-crimson

Derive computed value from multiple query caches that automatically updates when the caches change.

Hypothetical example:
export const useMessagesQuery = ({ chatId }: { chatId: string }) => {
return useQuery({
queryKey: ['messages', chatId],
queryFn: () => doSomething() });
};
export const useMessagesQuery = ({ chatId }: { chatId: string }) => {
return useQuery({
queryKey: ['messages', chatId],
queryFn: () => doSomething() });
};
- After opening multiple chats, I will have a query cache for each chat that stores its messages. - Let's assume I wanted to display the chat message with the newest creation date from all messages in all messages-${chatId} caches. I have read about query cache find all (https://tanstack.com/query/latest/docs/reference/QueryCache#querycachefindall), but how can I write this in a way that the computed value automatically updates whenever one of the underlying caches receives new data?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?