QueryObserver multiple keys
How i can observe any task? I want to know which task is created, updated or deleted.
i use mutations to create, update, delete tasks, maybe the tan stack query has its own mutation observer? (изменено)

7 Replies
other-emeraldOP•3y ago
Up
variable-lime•3y ago
Not sure I understand the question. Can you elaborate?
other-emeraldOP•3y ago
@TkDodo 🔮
There are several modules in my project that want to be notified when a
task changes. For example NotificationModule (remove the old notification and schedule a new one if task.datetime has changed, but I don't want to reschedule all notifications if one task has changed, I want more performance).
To notify my modules, I need to insert (for my opinion) code which complicate query declaration.
I read the docs several times and found awesome QueriesObserver it’s what I want, but for mutations, not query.
What can you advise for this situation, how to remove the use of external event emitter and notify my modules?
P.s. Thanks for the blog, I'm reading "Inside React Query", very impressed with the content, I think I understand the terms and internal code a much better than before.flat-fuchsia•3y ago
Is this https://tanstack.com/query/v4/docs/react/reference/MutationCache#mutationcachesubscribe what you’re looking for?
MutationCache | TanStack Query Docs
The MutationCache is the storage for mutations.
Normally, you will not interact with the MutationCache directly and instead use the QueryClient.
other-emeraldOP•3y ago
@donysukardi is a cache, not an observer. Why should I create an empty mutationcache instance and then call the subscribe method?
flat-fuchsia•3y ago
You can retrieve the mutationCache from queryClient and then subscribe to mutation events
other-emeraldOP•3y ago
Thank you 😊 I was wrong.