I have created a custom hook and a component:
export const useUserInfo = () => {
const query = useQuery({
queryKey: ["users-info"],
queryFn: () => fetchUserInfo(),
});
return query;
};
const Auth = () => {
const { instance } = useMsal();
const handleLoginPopup = async () => {
try {
const loginInfo = await instance.loginPopup(
loginRequest,
);
const responseData = useUserInfo()
console.log(responseData);
navigate("/home");
} catch (error) {
console.error(error);
}
};
}
Here, I am trying to call the useUserInfo
hook once the loginPopup
request is success. But somehow, I am not able to do this as I am getting an error regarding the hooks which can not be called inside conditions. Can any one help me with this?