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
PrabhathOP3y ago
similar thing works for creating a new row in table
Prabhath
PrabhathOP3y ago
Prabhath
PrabhathOP3y ago
It will be really helpful, if any one can share an example, thanks for checking this
rocawear
rocawear3y 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
Pluto3y 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
PrabhathOP3y ago
Thanks, for sharing this. I started using react-hook-form , it looks very clean now..

Did you find this page helpful?