react-hook-form 7.87.0 → 7.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/constants.d.ts +2 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/controller.d.ts +7 -35
  4. package/dist/controller.d.ts.map +1 -1
  5. package/dist/errorMessage.d.ts +27 -0
  6. package/dist/errorMessage.d.ts.map +1 -0
  7. package/dist/form.d.ts +7 -15
  8. package/dist/form.d.ts.map +1 -1
  9. package/dist/index.cjs.js +1 -1
  10. package/dist/index.cjs.js.map +1 -1
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.esm.mjs +390 -322
  14. package/dist/index.esm.mjs.map +1 -1
  15. package/dist/index.react-server.d.ts +3 -0
  16. package/dist/index.react-server.d.ts.map +1 -0
  17. package/dist/index.umd.js +1 -1
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/logic/createFormControl.d.ts.map +1 -1
  20. package/dist/logic/getResolverOptions.d.ts +1 -0
  21. package/dist/logic/getResolverOptions.d.ts.map +1 -1
  22. package/dist/logic/iterateFieldsByAction.d.ts +1 -1
  23. package/dist/logic/iterateFieldsByAction.d.ts.map +1 -1
  24. package/dist/logic/schemaErrorLookup.d.ts.map +1 -1
  25. package/dist/logic/validateField.d.ts.map +1 -1
  26. package/dist/react-server.esm.mjs +2535 -0
  27. package/dist/react-server.esm.mjs.map +1 -0
  28. package/dist/types/fields.d.ts +1 -0
  29. package/dist/types/fields.d.ts.map +1 -1
  30. package/dist/useController.d.ts +5 -17
  31. package/dist/useController.d.ts.map +1 -1
  32. package/dist/useFieldArray.d.ts +5 -30
  33. package/dist/useFieldArray.d.ts.map +1 -1
  34. package/dist/useForm.d.ts +7 -22
  35. package/dist/useForm.d.ts.map +1 -1
  36. package/dist/useFormContext.d.ts +10 -46
  37. package/dist/useFormContext.d.ts.map +1 -1
  38. package/dist/useFormState.d.ts +4 -23
  39. package/dist/useFormState.d.ts.map +1 -1
  40. package/dist/useWatch.d.ts +7 -140
  41. package/dist/useWatch.d.ts.map +1 -1
  42. package/dist/utils/cloneObject.d.ts.map +1 -1
  43. package/dist/utils/flatten.d.ts.map +1 -1
  44. package/dist/utils/formData.d.ts.map +1 -1
  45. package/dist/watch.d.ts +4 -16
  46. package/dist/watch.d.ts.map +1 -1
  47. package/package.json +10 -4
package/dist/useForm.d.ts CHANGED
@@ -1,31 +1,16 @@
1
1
  import type { FieldValues, UseFormProps, UseFormReturn } from './types';
2
2
  /**
3
- * Custom hook to manage the entire form.
3
+ * Core hook for managing a form. Returns all methods and state for
4
+ * registration, validation, and submission.
4
5
  *
5
- * @remarks
6
- * [API](https://react-hook-form.com/docs/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
7
- *
8
- * @param props - form configuration and validation parameters.
9
- *
10
- * @returns methods - individual functions to manage the form state. {@link UseFormReturn}
6
+ * @see [API](https://react-hook-form.com/docs/useform)
11
7
  *
12
8
  * @example
13
9
  * ```tsx
14
- * function App() {
15
- * const { register, handleSubmit, watch, formState: { errors } } = useForm();
16
- * const onSubmit = data => console.log(data);
17
- *
18
- * console.log(watch("example"));
19
- *
20
- * return (
21
- * <form onSubmit={handleSubmit(onSubmit)}>
22
- * <input defaultValue="test" {...register("example")} />
23
- * <input {...register("exampleRequired", { required: true })} />
24
- * {errors.exampleRequired && <span>This field is required</span>}
25
- * <button>Submit</button>
26
- * </form>
27
- * );
28
- * }
10
+ * const { register, handleSubmit, formState: { errors } } = useForm<FormValues>();
11
+ * <form onSubmit={handleSubmit(onSubmit)}>
12
+ * <input {...register("email", { required: true })} />
13
+ * </form>
29
14
  * ```
30
15
  */
31
16
  export declare function useForm<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>(props?: UseFormProps<TFieldValues, TContext, TTransformedValues>): UseFormReturn<TFieldValues, TContext, TTransformedValues>;
@@ -1 +1 @@
1
- {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EACZ,aAAa,EACd,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,OAAO,CACrB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CA4J3D"}
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EACZ,aAAa,EACd,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CACrB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAoK3D"}
@@ -1,64 +1,28 @@
1
1
  import React from 'react';
2
2
  import type { FieldValues, FormProviderProps, UseFormReturn } from './types';
3
3
  /**
4
- * This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
4
+ * Retrieves all `useForm` methods from the nearest `FormProvider`.
5
+ * Use in deeply nested components to avoid prop-drilling.
5
6
  *
6
- * @remarks
7
- * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
8
- *
9
- * @returns return all useForm methods
7
+ * @see [API](https://react-hook-form.com/docs/useformcontext)
10
8
  *
11
9
  * @example
12
10
  * ```tsx
13
- * function App() {
14
- * const methods = useForm();
15
- * const onSubmit = data => console.log(data);
16
- *
17
- * return (
18
- * <FormProvider {...methods} >
19
- * <form onSubmit={methods.handleSubmit(onSubmit)}>
20
- * <NestedInput />
21
- * <input type="submit" />
22
- * </form>
23
- * </FormProvider>
24
- * );
25
- * }
26
- *
27
- * function NestedInput() {
28
- * const { register } = useFormContext(); // retrieve all hook methods
29
- * return <input {...register("test")} />;
30
- * }
11
+ * const { register } = useFormContext<FormValues>();
31
12
  * ```
32
13
  */
33
14
  export declare const useFormContext: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>() => UseFormReturn<TFieldValues, TContext, TTransformedValues>;
34
15
  /**
35
- * A provider component that propagates the `useForm` methods to all children components via [React Context](https://react.dev/reference/react/useContext) API. To be used with {@link useFormContext}.
16
+ * Provides all `useForm` methods to the component tree via React Context.
17
+ * Pair with `useFormContext` to consume them in any descendant.
36
18
  *
37
- * @remarks
38
- * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
39
- *
40
- * @param props - all useForm methods
19
+ * @see [API](https://react-hook-form.com/docs/useformcontext)
41
20
  *
42
21
  * @example
43
22
  * ```tsx
44
- * function App() {
45
- * const methods = useForm();
46
- * const onSubmit = data => console.log(data);
47
- *
48
- * return (
49
- * <FormProvider {...methods} >
50
- * <form onSubmit={methods.handleSubmit(onSubmit)}>
51
- * <NestedInput />
52
- * <input type="submit" />
53
- * </form>
54
- * </FormProvider>
55
- * );
56
- * }
57
- *
58
- * function NestedInput() {
59
- * const { register } = useFormContext(); // retrieve all hook methods
60
- * return <input {...register("test")} />;
61
- * }
23
+ * <FormProvider {...methods}>
24
+ * <form onSubmit={methods.handleSubmit(onSubmit)}>{children}</form>
25
+ * </FormProvider>
62
26
  * ```
63
27
  */
64
28
  export declare const FormProvider: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>({ children, watch, getValues, getErrors, getFieldState, setError, clearErrors, setValue, setValues, trigger, formState, resetField, reset, resetDefaultValues, handleSubmit, unregister, control, register, setFocus, subscribe, }: FormProviderProps<TFieldValues, TContext, TTransformedValues>) => React.JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"useFormContext.d.ts","sourceRoot":"","sources":["../src/useFormContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAEV,WAAW,EACX,iBAAiB,EACjB,aAAa,EACd,MAAM,SAAS,CAAC;AAMjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,cAAc,GACzB,YAAY,SAAS,WAAW,EAChC,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,OAC9B,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAK1D,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,YAAY,GACvB,YAAY,SAAS,WAAW,EAChC,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,oOAqBC,iBAAiB,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,sBAuD/D,CAAC"}
1
+ {"version":3,"file":"useFormContext.d.ts","sourceRoot":"","sources":["../src/useFormContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAEV,WAAW,EACX,iBAAiB,EACjB,aAAa,EACd,MAAM,SAAS,CAAC;AAMjB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GACzB,YAAY,SAAS,WAAW,EAChC,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,OAC9B,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAK1D,CAAC;AAEJ;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GACvB,YAAY,SAAS,WAAW,EAChC,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,oOAqBC,iBAAiB,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,sBAuD/D,CAAC"}
@@ -1,32 +1,13 @@
1
1
  import type { FieldValues, UseFormStateProps, UseFormStateReturn } from './types';
2
2
  /**
3
- * Subscribes to each form state and isolates re-renders at the custom hook level. It has its own scope for form state subscriptions, so it will not affect other useFormState or useForm instances. Using this hook can reduce the re-render impact on large and complex form applications.
3
+ * Subscribes to form state with re-renders isolated to this hook.
4
+ * Optionally scope to specific field names to minimize re-render surface.
4
5
  *
5
- * @remarks
6
- * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
7
- *
8
- * @param props - Include options to specify fields to subscribe to. {@link UseFormStateReturn}
6
+ * @see [API](https://react-hook-form.com/docs/useformstate)
9
7
  *
10
8
  * @example
11
9
  * ```tsx
12
- * function App() {
13
- * const { register, handleSubmit, control } = useForm({
14
- * defaultValues: {
15
- * firstName: "firstName"
16
- * }});
17
- * const { dirtyFields } = useFormState({
18
- * control
19
- * });
20
- * const onSubmit = (data) => console.log(data);
21
- *
22
- * return (
23
- * <form onSubmit={handleSubmit(onSubmit)}>
24
- * <input {...register("firstName")} placeholder="First Name" />
25
- * {dirtyFields.firstName && <p>Field is dirty.</p>}
26
- * <input type="submit" />
27
- * </form>
28
- * );
29
- * }
10
+ * const { errors, isDirty } = useFormState({ control, name: "email" });
30
11
  * ```
31
12
  */
32
13
  export declare function useFormState<TFieldValues extends FieldValues = FieldValues, TTransformedValues = TFieldValues>(props?: UseFormStateProps<TFieldValues, TTransformedValues>): UseFormStateReturn<TFieldValues>;
@@ -1 +1 @@
1
- {"version":3,"file":"useFormState.d.ts","sourceRoot":"","sources":["../src/useFormState.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EAEX,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,YAAY,CAC1B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,kBAAkB,GAAG,YAAY,EAEjC,KAAK,CAAC,EAAE,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,CAAC,GAC1D,kBAAkB,CAAC,YAAY,CAAC,CAoElC"}
1
+ {"version":3,"file":"useFormState.d.ts","sourceRoot":"","sources":["../src/useFormState.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EAEX,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,kBAAkB,GAAG,YAAY,EAEjC,KAAK,CAAC,EAAE,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,CAAC,GAC1D,kBAAkB,CAAC,YAAY,CAAC,CAoElC"}
@@ -1,25 +1,5 @@
1
1
  import type { Control, DeepPartialSkipArrayKey, FieldPath, FieldPathValue, FieldPathValues, FieldValues } from './types';
2
- /**
3
- * Subscribes to all form value changes and re-renders at the hook level.
4
- *
5
- * @remarks
6
- *
7
- * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
8
- *
9
- * @param props - DefaultValue, disabled subscription, and exact name matching.
10
- *
11
- * @example
12
- * ```tsx
13
- * const { control } = useForm();
14
- * const values = useWatch({
15
- * control,
16
- * defaultValue: {
17
- * name: "data"
18
- * },
19
- * exact: false,
20
- * })
21
- * ```
22
- */
2
+ /** Watches the entire form; re-renders when any value changes. */
23
3
  export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TTransformedValues = TFieldValues>(props: {
24
4
  name?: undefined;
25
5
  defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
@@ -28,26 +8,7 @@ export declare function useWatch<TFieldValues extends FieldValues = FieldValues,
28
8
  exact?: boolean;
29
9
  compute?: undefined;
30
10
  }): DeepPartialSkipArrayKey<TFieldValues>;
31
- /**
32
- * Custom hook to subscribe to field changes and isolate re-rendering at the component level.
33
- *
34
- * @remarks
35
- *
36
- * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
37
- *
38
- * @param props - DefaultValue, disabled subscription, and exact name matching.
39
- *
40
- * @example
41
- * ```tsx
42
- * const { control } = useForm();
43
- * const values = useWatch({
44
- * control,
45
- * name: "fieldA",
46
- * defaultValue: "default value",
47
- * exact: false,
48
- * })
49
- * ```
50
- */
11
+ /** Watches a single field by name. */
51
12
  export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformedValues = TFieldValues>(props: {
52
13
  name: TFieldName;
53
14
  defaultValue?: FieldPathValue<TFieldValues, TFieldName>;
@@ -56,24 +17,7 @@ export declare function useWatch<TFieldValues extends FieldValues = FieldValues,
56
17
  exact?: boolean;
57
18
  compute?: undefined;
58
19
  }): FieldPathValue<TFieldValues, TFieldName>;
59
- /**
60
- * Custom hook to subscribe to field changes and use a compute function to produce state updates.
61
- *
62
- * @remarks
63
- *
64
- * [API](https://react-hook-form.com/docs/usewatch)
65
- *
66
- * @param props - DefaultValue, disabled subscription, and exact name matching.
67
- *
68
- * @example
69
- * ```tsx
70
- * const { control } = useForm();
71
- * const values = useWatch({
72
- * control,
73
- * compute: (formValues) => formValues.fieldA
74
- * })
75
- * ```
76
- */
20
+ /** Watches the entire form and derives a value via `compute`. */
77
21
  export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TTransformedValues = TFieldValues, TComputeValue = unknown>(props: {
78
22
  name?: undefined;
79
23
  defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
@@ -82,27 +26,7 @@ export declare function useWatch<TFieldValues extends FieldValues = FieldValues,
82
26
  exact?: boolean;
83
27
  compute: (formValues: TFieldValues) => TComputeValue;
84
28
  }): TComputeValue;
85
- /**
86
- * Custom hook to subscribe to field changes and use a compute function to produce state updates.
87
- *
88
- * @remarks
89
- *
90
- * [API](https://react-hook-form.com/docs/usewatch)
91
- *
92
- * @param props - DefaultValue, disabled subscription, and exact name matching.
93
- *
94
- * @example
95
- * ```tsx
96
- * const { control } = useForm();
97
- * const values = useWatch({
98
- * control,
99
- * name: "fieldA",
100
- * defaultValue: "default value",
101
- * exact: false,
102
- * compute: (fieldValue) => fieldValue === "data" ? fieldValue : null,
103
- * })
104
- * ```
105
- */
29
+ /** Watches a single field and derives a value via `compute`. */
106
30
  export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformedValues = TFieldValues, TComputeValue = unknown>(props: {
107
31
  name: TFieldName;
108
32
  defaultValue?: FieldPathValue<TFieldValues, TFieldName>;
@@ -111,29 +35,7 @@ export declare function useWatch<TFieldValues extends FieldValues = FieldValues,
111
35
  exact?: boolean;
112
36
  compute: (fieldValue: FieldPathValue<TFieldValues, TFieldName>) => TComputeValue;
113
37
  }): TComputeValue;
114
- /**
115
- * Custom hook to subscribe to field changes and isolate re-rendering at the component level.
116
- *
117
- * @remarks
118
- *
119
- * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
120
- *
121
- * @param props - DefaultValue, disabled subscription, and exact name matching.
122
- *
123
- * @example
124
- * ```tsx
125
- * const { control } = useForm();
126
- * const values = useWatch({
127
- * control,
128
- * name: ["fieldA", "fieldB"],
129
- * defaultValue: {
130
- * fieldA: "data",
131
- * fieldB: "data"
132
- * },
133
- * exact: false,
134
- * })
135
- * ```
136
- */
38
+ /** Watches multiple fields by name array. */
137
39
  export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldNames extends readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[], TTransformedValues = TFieldValues>(props: {
138
40
  name: readonly [...TFieldNames];
139
41
  defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
@@ -142,30 +44,7 @@ export declare function useWatch<TFieldValues extends FieldValues = FieldValues,
142
44
  exact?: boolean;
143
45
  compute?: undefined;
144
46
  }): FieldPathValues<TFieldValues, TFieldNames>;
145
- /**
146
- * Custom hook to subscribe to field changes and use a compute function to produce state updates.
147
- *
148
- * @remarks
149
- *
150
- * [API](https://react-hook-form.com/docs/usewatch)
151
- *
152
- * @param props - DefaultValue, disabled subscription, and exact name matching.
153
- *
154
- * @example
155
- * ```tsx
156
- * const { control } = useForm();
157
- * const values = useWatch({
158
- * control,
159
- * name: ["fieldA", "fieldB"],
160
- * defaultValue: {
161
- * fieldA: "data",
162
- * fieldB: 0
163
- * },
164
- * compute: ([fieldAValue, fieldBValue]) => fieldB === 2 ? fieldA : null,
165
- * exact: false,
166
- * })
167
- * ```
168
- */
47
+ /** Watches multiple fields and derives a value via `compute`. */
169
48
  export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldNames extends readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[], TTransformedValues = TFieldValues, TComputeValue = unknown>(props: {
170
49
  name: readonly [...TFieldNames];
171
50
  defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
@@ -174,18 +53,6 @@ export declare function useWatch<TFieldValues extends FieldValues = FieldValues,
174
53
  exact?: boolean;
175
54
  compute: (fieldValue: FieldPathValues<TFieldValues, TFieldNames>) => TComputeValue;
176
55
  }): TComputeValue;
177
- /**
178
- * Custom hook to subscribe to field changes and isolate re-rendering at the component level.
179
- *
180
- * @remarks
181
- *
182
- * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
183
- *
184
- * @example
185
- * ```tsx
186
- * // Can skip passing down the control into useWatch if the form is wrapped with FormProvider
187
- * const values = useWatch()
188
- * ```
189
- */
56
+ /** Watches the entire form; reads `control` from `FormProvider` context. */
190
57
  export declare function useWatch<TFieldValues extends FieldValues = FieldValues>(): DeepPartialSkipArrayKey<TFieldValues>;
191
58
  //# sourceMappingURL=useWatch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWatch.d.ts","sourceRoot":"","sources":["../src/useWatch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,OAAO,EACP,uBAAuB,EACvB,SAAS,EACT,cAAc,EACd,eAAe,EACf,WAAW,EAGZ,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CACtB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,kBAAkB,GAAG,YAAY,EACjC,KAAK,EAAE;IACP,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,YAAY,CAAC,EAAE,uBAAuB,CAAC,YAAY,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE,kBAAkB,CAAC,CAAC;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB,GAAG,uBAAuB,CAAC,YAAY,CAAC,CAAC;AAC1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,QAAQ,CACtB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,UAAU,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,EACpE,kBAAkB,GAAG,YAAY,EACjC,KAAK,EAAE;IACP,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,CAAC,EAAE,cAAc,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACxD,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE,kBAAkB,CAAC,CA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","sourceRoot":"","sources":["../../src/utils/cloneObject.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CA+BjD"}
1
+ {"version":3,"file":"cloneObject.d.ts","sourceRoot":"","sources":["../../src/utils/cloneObject.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAgCjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/utils/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAS5C,eAAO,MAAM,OAAO,GAAI,KAAK,WAAW,gBAqBvC,CAAC"}
1
+ {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/utils/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAY5C,eAAO,MAAM,OAAO,GAAI,KAAK,WAAW,gBAsBvC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"formData.d.ts","sourceRoot":"","sources":["../../src/utils/formData.ts"],"names":[],"mappings":"AAEA,iBAAS,cAAc,CAAC,IAAI,EAAE,GAAG,YAUhC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"formData.d.ts","sourceRoot":"","sources":["../../src/utils/formData.ts"],"names":[],"mappings":"AAGA,iBAAS,cAAc,CAAC,IAAI,EAAE,GAAG,YA0BhC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
package/dist/watch.d.ts CHANGED
@@ -1,27 +1,15 @@
1
1
  import type { FieldPath, FieldValues, WatchProps } from './types';
2
2
  /**
3
- * Watch component that subscribes to form field changes and re-renders when watched fields update.
3
+ * Component wrapper around `useWatch`. Re-renders only when watched fields change.
4
4
  *
5
- * @param control - The form control object from useForm
6
- * @param name - Can be field name, array of field names, or undefined to watch the entire form
7
- * @param disabled - Disable subscription
8
- * @param exact - Whether to watch exact field names or not
9
- * @param defaultValue - The default value to use if the field is not yet set
10
- * @param compute - Function to compute derived values from watched fields
11
- * @param render - The function that receives watched values and returns ReactNode
12
- * @returns The result of calling render function with watched values
5
+ * @see [API](https://react-hook-form.com/docs/usewatch)
13
6
  *
14
7
  * @example
15
- * The `Watch` component only re-render when the values of `foo`, `bar`, and `baz.qux` change.
16
- * The types of `foo`, `bar`, and `baz.qux` are precisely inferred.
17
- *
18
8
  * ```tsx
19
- * const { control } = useForm();
20
- *
21
9
  * <Watch
22
10
  * control={control}
23
- * names={['foo', 'bar', 'baz.qux']}
24
- * render={([foo, bar, baz_qux]) => <div>{foo}{bar}{baz_qux}</div>}
11
+ * names={["foo", "bar"]}
12
+ * render={([foo, bar]) => <span>{foo} {bar}</span>}
25
13
  * />
26
14
  * ```
27
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,UAAU,EAEX,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,KAAK,GAChB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,UAAU,SACN,SAAS,CAAC,YAAY,CAAC,GACvB,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,GAChE,SAAS,CAAC,YAAY,CAAC,EAAE,GACzB,SAAS,SAAS,CAAC,YAAY,CAAC,EAAE,GAClC,SAAS,GAAG,SAAS,EACzB,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,aAAa,GAAG,SAAS,EAEzB,OAAO,UAAU,CACf,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,aAAa,CACd,4DAQA,CAAC"}
1
+ {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,UAAU,EAEX,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAChB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,UAAU,SACN,SAAS,CAAC,YAAY,CAAC,GACvB,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,GAChE,SAAS,CAAC,YAAY,CAAC,EAAE,GACzB,SAAS,SAAS,CAAC,YAAY,CAAC,EAAE,GAClC,SAAS,GAAG,SAAS,EACzB,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,aAAa,GAAG,SAAS,EAEzB,OAAO,UAAU,CACf,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,aAAa,CACd,4DAQA,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-hook-form",
3
3
  "description": "Performant, flexible and extensible forms library for React Hooks",
4
- "version": "7.87.0",
4
+ "version": "7.89.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.mjs",
7
7
  "umd:main": "dist/index.umd.js",
@@ -18,12 +18,13 @@
18
18
  "./package.json": "./package.json",
19
19
  ".": {
20
20
  "types": "./dist/index.d.ts",
21
+ "react-server": "./dist/react-server.esm.mjs",
21
22
  "import": "./dist/index.esm.mjs",
22
23
  "require": "./dist/index.cjs.js"
23
24
  }
24
25
  },
25
26
  "scripts": {
26
- "clean": "rimraf dist",
27
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true, maxRetries: 3, retryDelay: 100 })\"",
27
28
  "prepare": "husky",
28
29
  "prebuild": "pnpm clean",
29
30
  "build": "pnpm build:modern",
@@ -98,7 +99,6 @@
98
99
  "prettier": "^3.8.4",
99
100
  "react": "^19.2.7",
100
101
  "react-dom": "^19.2.7",
101
- "rimraf": "^6.1.3",
102
102
  "rollup": "^4.62.0",
103
103
  "rollup-plugin-typescript2": "^0.36.0",
104
104
  "tsx": "^4.22.4",
@@ -111,13 +111,19 @@
111
111
  "files": [
112
112
  {
113
113
  "path": "./dist/index.cjs.js",
114
- "maxSize": "14.0 kB"
114
+ "maxSize": "15.0 kB"
115
115
  }
116
116
  ]
117
117
  },
118
118
  "peerDependencies": {
119
+ "@types/react": "*",
119
120
  "react": "^16.8.0 || ^17 || ^18 || ^19"
120
121
  },
122
+ "peerDependenciesMeta": {
123
+ "@types/react": {
124
+ "optional": true
125
+ }
126
+ },
121
127
  "lint-staged": {
122
128
  "*.{js,ts,tsx}": [
123
129
  "pnpm lint:fix",