-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStep2Form.tsx
More file actions
34 lines (26 loc) · 930 Bytes
/
Copy pathStep2Form.tsx
File metadata and controls
34 lines (26 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useForm, SubmitHandler } from "react-hook-form"
export type Inputs = {
lastname: string
firstname: string
}
export function Step2Form(props: {
onSubmit: (dat: Inputs) => void
}) {
const {
register,
handleSubmit,
watch,
formState: { errors },
} = useForm<Inputs>()
const onSubmit: SubmitHandler<Inputs> = (data) => props.onSubmit(data);
return <form onSubmit={handleSubmit(onSubmit)}>
<input {...register("firstname", { required: true, maxLength: 10 })} data-testid="firstname-input"/>
{errors.firstname
? <span>This field is invalid</span>
: <span>The firstname is valid</span>
}
<input {...register("lastname", { maxLength: 20 })} data-testid="lastname-input"/>
<span>The form has {Object.keys(errors).length} errors</span>
<input type="submit" data-testid="step2-button" value="Save" />
</form>
}