MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / FormStateWithSchema

Function FormStateWithSchema

app/src/formStateWithSchema.tsx:20–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18 .required();
19
20const FormStateWithSchema: React.FC = () => {
21 const { mode } = useParams();
22 const {
23 register,
24 handleSubmit,
25 formState: {
26 dirtyFields,
27 isSubmitted,
28 submitCount,
29 touchedFields,
30 isDirty,
31 isSubmitting,
32 isSubmitSuccessful,
33 isValid,
34 },
35 reset,
36 } = useForm<{
37 firstName: string;
38 lastName: string;
39 select: string;
40 radio: string | null;
41 checkbox: boolean;
42 }>({
43 resolver: yupResolver(validationSchema),
44 mode: mode as keyof ValidationMode,
45 defaultValues: {
46 firstName: '',
47 lastName: '',
48 select: '',
49 checkbox: false,
50 radio: null,
51 },
52 });
53 const onSubmit = () => {};
54
55 renderCounter++;
56
57 return (
58 <form onSubmit={handleSubmit(onSubmit)}>
59 <input {...register('firstName')} placeholder="firstName" />
60 <input {...register('lastName')} placeholder="lastName" />
61 <select {...register('select')}>
62 <option value="">Select</option>
63 <option value={1}>1</option>
64 <option value={2}>1</option>
65 </select>
66 Radio1
67 <input type="radio" {...register('radio')} value="1" />
68 Radio2
69 <input type="radio" {...register('radio')} value="2" />
70 Radio3
71 <input type="radio" {...register('radio')} value="3" />
72 <input type="checkbox" {...register('checkbox')} />
73 <button id="submit">Submit</button>
74 <button type="button" onClick={() => reset()} id="resetForm">
75 Reset
76 </button>
77 <div id="state">

Callers

nothing calls this directly

Calls 4

useFormFunction · 0.85
handleSubmitFunction · 0.85
registerFunction · 0.85
resetFunction · 0.85

Tested by

no test coverage detected