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?
7 Replies
absent-sapphireOP•12mo ago
in this case, the query gets disabled once
query.state.data
becomes undefined. I also want to execute a function when this happens.correct-apricot•12mo 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
absent-sapphireOP•12mo 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?
correct-apricot•12mo ago
What's the use case?
xenial-black•12mo 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.
absent-sapphireOP•12mo 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 functioncorrect-apricot•12mo 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 🤷♂️