Let's say I have a query, useFetchUser() and a mutation, useMutateUser(). When my component is rendered I want to fetch the current user and then execute the mutation after the query completion. So I have something like this:
const {data} = useFetchUser()
const {mutate} = useMutateUser()
useEffect(() => {
if(data) {
mutate()
}
}, [data, mutate])
Now when I check in the network tab I see that the mutation starts while the query is still pending. What am I doing wrong?
datawill beundefinedfor as long as the query is initially loading, your condition prevents the mutation from running. Generally, I would put side effects into theonSuccesscallback of the query.