MCPcopy Index your code
hub / github.com/react-hook-form/react-hook-form / useFormState

Function useFormState

src/useFormState.ts:43–106  ·  view source on GitHub ↗
(
  props?: UseFormStateProps<TFieldValues, TTransformedValues>,
)

Source from the content-addressed store, hash-verified

41 * ```
42 */
43export function useFormState<
44 TFieldValues extends FieldValues = FieldValues,
45 TTransformedValues = TFieldValues,
46>(
47 props?: UseFormStateProps<TFieldValues, TTransformedValues>,
48): UseFormStateReturn<TFieldValues> {
49 const formControl = useFormControlContext<
50 TFieldValues,
51 any,
52 TTransformedValues
53 >();
54 const { control = formControl, disabled, name, exact } = props || {};
55 const [formState, updateFormState] = React.useState<FormState<TFieldValues>>(
56 () => ({
57 ...control._formState,
58 defaultValues:
59 control._defaultValues as FormState<TFieldValues>['defaultValues'],
60 }),
61 );
62 const _localProxyFormState = React.useRef({
63 isDirty: false,
64 isLoading: false,
65 dirtyFields: false,
66 touchedFields: false,
67 validatingFields: false,
68 isValidating: false,
69 isValid: false,
70 errors: false,
71 });
72
73 useIsomorphicLayoutEffect(
74 () =>
75 control._subscribe({
76 name,
77 formState: _localProxyFormState.current,
78 exact,
79 callback: (formState) => {
80 !disabled &&
81 updateFormState({
82 ...control._formState,
83 ...formState,
84 defaultValues:
85 control._defaultValues as FormState<TFieldValues>['defaultValues'],
86 });
87 },
88 }),
89 [name, disabled, exact],
90 );
91
92 React.useEffect(() => {
93 _localProxyFormState.current.isValid && control._setValid(true);
94 }, [control]);
95
96 return React.useMemo(
97 () =>
98 getProxyFormState(
99 formState,
100 control,

Callers 15

FormStateSubscribeFunction · 0.90
useControllerFunction · 0.90
AppFunction · 0.90
TestFormStateFunction · 0.90
Test1Function · 0.90
ObserverFunction · 0.90
NotObserverFunction · 0.90
TestFunction · 0.90
ChildFunction · 0.90
Test1Function · 0.90
AppFunction · 0.90

Calls 1

useFormControlContextFunction · 0.90

Tested by 15

AppFunction · 0.72
TestFormStateFunction · 0.72
Test1Function · 0.72
ObserverFunction · 0.72
NotObserverFunction · 0.72
TestFunction · 0.72
ChildFunction · 0.72
Test1Function · 0.72
AppFunction · 0.72
DirtyStateFunction · 0.72
InputFunction · 0.72
FormFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…