Can anyone share an example trpc mutation based onSubmit values from a form

I keep getting Hooks can only be called from React component.
6 Replies
Prabhath
PrabhathOP2y ago
similar thing works for creating a new row in table
Prabhath
PrabhathOP2y ago
Prabhath
PrabhathOP2y ago
It will be really helpful, if any one can share an example, thanks for checking this
rocawear
rocawear2y ago
GitHub
t3-credentials/RegisterForm.tsx at main · ruhap/t3-credentials
t3 stack with next-auth credential provider. Contribute to ruhap/t3-credentials development by creating an account on GitHub.
Pluto
Pluto2y ago
You're declaring mutation itself in function which is wrong and not needed You can simply put your mutation at the top of your component like
const mutation = trpc.cform.useMutation()
const mutation = trpc.cform.useMutation()
And later on in your submit function .
const onSubmit = async () => {

// ...
await mutation.mutateAsync(nform)

console.log('completed mutation successfully');
const onSubmit = async () => {

// ...
await mutation.mutateAsync(nform)

console.log('completed mutation successfully');
Prabhath
PrabhathOP2y ago
Thanks, for sharing this. I started using react-hook-form , it looks very clean now..
Want results from more Discord servers?
Add your server