On my root component, I have used use query to get the user details. but the problem is before I sign up or sign in, it refeches too many times. as a result I can't even fill up the signUp/signIn form smoothly.
Is there any way, so that It will refetch only if the callback function returns no error?
This is, what I have tried
const FetchCurrentUser = async () => {
setAuthToken(localStorage.token);
const {
data: { user },
} = await axios.get(`${process.env.API_URL}/api/users/auth`);
return user;
};
const RouterController = () => {
const { data: updatedUser, isLoading, error: fetchError } = useQuery(
"user",
FetchCurrentUser,
);
}
refetch
method get called? – Vichy