T
TanStack15mo ago
quickest-silver

How to trigger a function when a query is disabled?

I have a query that gets disabled once a certain condition is met (via setting the refetchInterval to false). I also want to execute a function once the query is disabled. How can I do it?
No description
7 Replies
quickest-silver
quickest-silverOP15mo ago
in this case, the query gets disabled once query.state.data becomes undefined. I also want to execute a function when this happens.
rare-sapphire
rare-sapphire15mo ago
I would put it in the query function? at the end, you check the data property and if it's undefined, you call yuour function
quickest-silver
quickest-silverOP15mo ago
that feels a bit anti pattern, no? i dont think a query function should be responsible for changing external state. @Kalo0m @TkDodo 🔮 any help with this, please?
ratty-blush
ratty-blush15mo ago
What's the use case?
protestant-coral
protestant-coral15mo ago
I don't understand the anti pattern argument. You want to do what you want to do. Seems pretty shut and dry to me.
quickest-silver
quickest-silverOP15mo ago
A mutation is triggered on some conditions. This query monitors the result, but the response is very heavy. I want to disable the query as soon as query.state.data becomes undefined and run another function
ratty-blush
ratty-blush15mo ago
query.state.data cannot become undefined because undefined is not a valid value to be returned from the queryFn. setting refetchInterval to false doesnt "disable" a query. I'm stil confused about what you are trying to achieve 🤷‍♂️

Did you find this page helpful?