Son
Explore posts from serverstrpc hook pattern. This works, but I’m not convinced…
there are no implementation differences between query and mutation according to the docs, its just semantics. Also by definition it’s a query, because its checking if the database exists in the database only.
7 replies
correct way to call TRPC inside a function
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}/>
‘’’
13 replies
TRPC Testing Wrapper - Unit Testing components that contain a query (Not testing the query it self)
Thanks for entering this thread! Really appreciate it. I’m a total noob tbh but I’m learning as i go.
Why do i need to add that and how should I implement it.
Im guessing i would need a mutation aswell? Or am I mixing things up here?
14 replies