-
Hi! I want to disable refetch under certain conditions. Is there any good API for this use case? async function getRandom() {
return Math.random() * 10 | 0
}
const Component = () => {
const { data } = useQuery('random', getRandom, {
refetchInterval: 300,
// I want to disable refetching when data is 3...
// something like that?
enabled: data => data !== 3
})
return (
<span>{ data }</span>
);
}; |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Nov 7, 2020
Replies: 1 comment 2 replies
-
enabled is just a flag, it doesn’t take a function. I don’t think you can make a query dependent on itself like that. You could add a useEffect that sets a boolean state variable, and you enable/disable your query depending on that. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
tannerlinsley
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
enabled is just a flag, it doesn’t take a function. I don’t think you can make a query dependent on itself like that. You could add a useEffect that sets a boolean state variable, and you enable/disable your query depending on that.