.oxyzen
02/12/2024, 5:48 AM.oxyzen
02/12/2024, 5:48 AMtsx
export const useData = () => {
const session = useSessionContext();
if (session.loading) {
return { data: null, isLoading: true, error: null };
}
const {
data,
isLoading,
error,
} = useQuery({
queryKey: ['somedata'],
queryFn: async () => {
const res = await axios.get(API+'/'+session.userId).then((response) => response.data);
return res[0];
},
});
return {
data,
isLoading,
error,
};
};
.oxyzen
02/12/2024, 5:49 AM.oxyzen
02/12/2024, 5:51 AMrendered more hooks than during the previous render
error since I'm using if statement with hooks..oxyzen
02/12/2024, 5:52 AMrp_st
02/12/2024, 6:25 AMrp_st
02/12/2024, 6:25 AM.oxyzen
02/12/2024, 8:02 AMuseSessionContext
or using session.loading.rp_st
02/12/2024, 8:03 AMqueryFn
function, you can call await Session.doesSessionExist
, or await Session.getAccessTokenPayloadSecurely()
and so on. So don't use the useSessionContext hook we have for this use case.oxyzen
02/12/2024, 8:29 AMrp_st
02/12/2024, 8:30 AM