-
useQuery nicely supports dependent queries already. const [enabled, setEnabled] = useState(true);
const { isLoading, data } = useQuery(/* ... */, {enabled});
const state = data?.state;
useEffect(() => {
if (state === 'finished') setEnabled(false);
}, [state]); (via How to use the react-query result inside the QueryOptions?) I think a functional form of QueryOptions would be great: const { isLoading, data } = useQuery(
"data-querykey-" + id,
() => api.getData({ id }),
(data) => {
enabled: data?.state !== "finished",
refetchInterval: 3000,
}
); with data being |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
May 16, 2023
Replies: 1 comment
-
refetchInterval can be a function to support exactly this usecase |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
cachius
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
refetchInterval can be a function to support exactly this usecase