T
TanStack2y ago
like-gold

angular-use-query: track refetches

Hello, I'm using angular v17. I would like to monitor the query changes from tanstack query, and publish the results to a local store of mine. Basically, each time it refetches, i would like to be notified somehow, so i can retrieve the latest data,errors,isFetching,etc and publish them. I could imagine an API like this:
const query = injectQuery(() => ({
queryKey,
queryFn,
}));

query.monitorChanges((data,isError,isFetching,...)=>{
publisher.publish({
...
});
})
const query = injectQuery(() => ({
queryKey,
queryFn,
}));

query.monitorChanges((data,isError,isFetching,...)=>{
publisher.publish({
...
});
})
If there are other approaches to this problem, please enlighten me
1 Reply
adverse-sapphire
adverse-sapphire2y ago
Hmm, why would you want to put the results of query into a store? The ides is that query has its own store, and you would just call injectQuery wherever you need access to the data...

Did you find this page helpful?