correct way to call TRPC inside a function

AAyo12/7/2022
i want a user to be able to sign after they have a clicked a button but i get a hooks error. can anyone help with this?
AAyo12/7/2022
UUUnknown User12/7/2022
2 Messages Not Public
Sign In & Join Server To View
AAyo12/7/2022
Thank you, i made use of the enabled property, and used refectch() in the component. I’m going to export it into. Custom hook and rejig it.
AAyo12/11/2022
This is the pattern I came up with.

I want to call my route when a button is clicked and have access to isLoading, onError etc…

I have implemented a pattern using ‘’refetch()’’ but it doesn’t feel ‘correct’ is there a better way of doing this. I will also create a custom hook out of it.

‘’’js
const { refetch } = trpc.authDomain.signIn.useQuery(
{ email: userEmail },
{
enabled: false,
onError: (e: any) => {
console.log('there was an error with the endpoint');
},
}
);

async function isEmailVerified() {
const response = await refetch();
const verification = response.data;

// i want to access isLoading directly without writing many lines of new code which i would have to with this current approach

if (verification?.status === 'tryAgain') {
console.log('email not verified');
setHasInitiatedSignIn(true);
}

if (verification?.status === 'ok') {
console.log('user can now verify code sent to their email address');
setHasInitiatedSignIn(true);
}
}

Return <button onClick={isEmailVerified}/>

‘’’
UUUnknown User12/11/2022
Message Not Public
Sign In & Join Server To View
AAyo12/11/2022
This helped ill try some variation of this for my needs. thanks
UUUnknown User12/11/2022
Message Not Public
Sign In & Join Server To View
AAyo12/11/2022
How would you handle ‘isLoading’
UUUnknown User12/11/2022
Message Not Public
Sign In & Join Server To View
AAyo12/11/2022
Ill try this approach, thanks
Mmsalsbery12/11/2022
You’ll find it much easier than fighting useQuery I reckon 😉