MCPcopy
hub / github.com/react-hook-form/react-hook-form / ConditionField

Function ConditionField

app/src/useFieldArrayUnregister.tsx:17–44  ·  view source on GitHub ↗
({
  control,
  index,
  unregister,
}: {
  control: Control<FormInputs>;
  unregister: UseFormReturn<FormInputs>['unregister'];
  index: number;
  fields: T;
})

Source from the content-addressed store, hash-verified

15};
16
17const ConditionField = <T extends any[]>({
18 control,
19 index,
20 unregister,
21}: {
22 control: Control<FormInputs>;
23 unregister: UseFormReturn<FormInputs>['unregister'];
24 index: number;
25 fields: T;
26}) => {
27 const output = useWatch({
28 name: 'data',
29 control,
30 });
31
32 React.useEffect(() => {
33 return () => {
34 unregister(`data.${index}.conditional` as const, {
35 keepDirty: true,
36 keepTouched: true,
37 });
38 };
39 }, [unregister, index]);
40
41 return output?.[index]?.name === 'bill' ? (
42 <input {...control.register(`data.${index}.conditional`)} />
43 ) : null;
44};
45
46const UseFieldArrayUnregister: React.FC = () => {
47 const {

Callers

nothing calls this directly

Calls 2

useWatchFunction · 0.85
unregisterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…