React-hook-form: How to run some code after handleSubmit executed?

Created on 9 Mar 2020  ·  1Comment  ·  Source: react-hook-form/react-hook-form

Please consider asking the question at our spectrum channel.

I've tried the spectrum channel chat and it keeps eating my messages and I don't know why. I'm so sad 😢

https://spectrum.chat/react-hook-form

Describe the question?
I'd like to show a toast with error message after handleSubmit executed. But I don't know how to "handle this event". Maybe we could have two callbacks arguments like handleSubmit(resolved, rejected) ?

To Reproduce
No need to reproduce.

Codesandbox link
Take this from Examples - Register Error Messages as an example.
https://codesandbox.io/s/o766kp4z05

Screenshots
No screenshots.

Additional context

114 looks similar.

question

Most helpful comment

const onSubmit = () => {
  // do your logic here
}

useEffect(() => {
  // do your logic here
}, [errors])

handleSubmit(onSubmit)

>All comments

const onSubmit = () => {
  // do your logic here
}

useEffect(() => {
  // do your logic here
}, [errors])

handleSubmit(onSubmit)
Was this page helpful?
0 / 5 - 0 ratings