Skip to content

Commit f719ace

Browse files
committed
add SubmitErrorHandler example
1 parent 847f8f0 commit f719ace

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/content/ts.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,37 @@ export default function App() {
8484

8585
---
8686

87+
## \</> SubmitErrorHandler {#SubmitErrorHandler}
88+
89+
```typescript copy
90+
import React from "react"
91+
import { useForm, SubmitHandler, SubmitErrorHandler } from "react-hook-form"
92+
93+
type FormValues = {
94+
firstName: string
95+
lastName: string
96+
email: string
97+
}
98+
99+
export default function App() {
100+
const { register, handleSubmit } = useForm<FormValues>()
101+
const onSubmit: SubmitHandler<FormValues> = (data) => console.log(data)
102+
const onError: SubmitErrorHandler<FormValues> = (errors) => console.log(errors);
103+
104+
return (
105+
<form onSubmit={handleSubmit(onSubmit, onError)}>
106+
<input {...register("firstName")} />
107+
<input {...register("lastName")} />
108+
<input type="email" {...register("email")} />
109+
110+
<input type="submit" />
111+
</form>
112+
)
113+
}
114+
```
115+
116+
---
117+
87118
## \</> Control {#Control}
88119

89120
```typescript copy sandbox="https://codesandbox.io/s/control-2mg07"

0 commit comments

Comments
 (0)