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

Function Field

app/src/controller.tsx:46–201  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44const PureReactSelect = React.memo(ReactSelect);
45
46export default function Field() {
47 const { mode } = useParams();
48 const methods = useForm<Form>({
49 defaultValues,
50 mode: mode as keyof ValidationMode,
51 });
52 const {
53 handleSubmit,
54 formState: { errors },
55 reset,
56 control,
57 } = methods;
58
59 const [, setRerender] = React.useState(0);
60 renderCount++;
61
62 const rerender = () => setRerender(Math.random());
63
64 return (
65 <form onSubmit={handleSubmit(() => {})}>
66 <div className="container">
67 <section id="input-checkbox">
68 <label>MUI Checkbox</label>
69 <Controller
70 name="Checkbox"
71 control={control}
72 rules={{ required: true }}
73 render={({ field: props }) => (
74 <Checkbox
75 {...props}
76 onChange={(e) => props.onChange(e.target.checked)}
77 />
78 )}
79 />
80 </section>
81
82 {errors.Checkbox && <p id="Checkbox">Checkbox Error</p>}
83
84 <section id="input-radio-group">
85 <label>Radio Group</label>
86 <Controller
87 render={({ field }) => (
88 <RadioGroup aria-label="gender" {...field} name="gender1">
89 <FormControlLabel
90 value="female"
91 control={<Radio />}
92 label="Female"
93 />
94 <FormControlLabel
95 value="male"
96 control={<Radio />}
97 label="Male"
98 />
99 <FormControlLabel
100 value="other"
101 control={<Radio />}
102 label="Other"
103 />

Callers

nothing calls this directly

Calls 3

useFormFunction · 0.85
handleSubmitFunction · 0.85
resetFunction · 0.85

Tested by

no test coverage detected