react-hook-form 8.0.0-alpha.0 → 8.0.0-alpha.3

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/README.md +387 -317
  2. package/dist/controller.d.ts +42 -0
  3. package/dist/controller.d.ts.map +1 -1
  4. package/dist/index.cjs.js +1 -1
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.esm.mjs +694 -333
  7. package/dist/index.esm.mjs.map +1 -1
  8. package/dist/index.umd.js +1 -1
  9. package/dist/index.umd.js.map +1 -1
  10. package/dist/logic/createFormControl.d.ts +1 -1
  11. package/dist/logic/createFormControl.d.ts.map +1 -1
  12. package/dist/logic/focusFieldBy.d.ts.map +1 -1
  13. package/dist/logic/getResolverOptions.d.ts +1 -1
  14. package/dist/logic/shouldRenderFormState.d.ts.map +1 -1
  15. package/dist/logic/updateFieldArrayRootError.d.ts +4 -0
  16. package/dist/logic/updateFieldArrayRootError.d.ts.map +1 -0
  17. package/dist/logic/validateField.d.ts +1 -1
  18. package/dist/logic/validateField.d.ts.map +1 -1
  19. package/dist/types/controller.d.ts +24 -3
  20. package/dist/types/controller.d.ts.map +1 -1
  21. package/dist/types/errors.d.ts +9 -2
  22. package/dist/types/errors.d.ts.map +1 -1
  23. package/dist/types/fieldArray.d.ts +173 -8
  24. package/dist/types/fieldArray.d.ts.map +1 -1
  25. package/dist/types/form.d.ts +395 -29
  26. package/dist/types/form.d.ts.map +1 -1
  27. package/dist/types/resolvers.d.ts +3 -3
  28. package/dist/types/resolvers.d.ts.map +1 -1
  29. package/dist/types/utils.d.ts +4 -5
  30. package/dist/types/utils.d.ts.map +1 -1
  31. package/dist/types/validator.d.ts +1 -1
  32. package/dist/types/validator.d.ts.map +1 -1
  33. package/dist/useController.d.ts +24 -0
  34. package/dist/useController.d.ts.map +1 -1
  35. package/dist/useFieldArray.d.ts +39 -2
  36. package/dist/useFieldArray.d.ts.map +1 -1
  37. package/dist/useForm.d.ts +30 -1
  38. package/dist/useForm.d.ts.map +1 -1
  39. package/dist/useFormContext.d.ts +62 -2
  40. package/dist/useFormContext.d.ts.map +1 -1
  41. package/dist/useFormState.d.ts +30 -0
  42. package/dist/useFormState.d.ts.map +1 -1
  43. package/dist/useWatch.d.ts +68 -4
  44. package/dist/useWatch.d.ts.map +1 -1
  45. package/dist/utils/compact.d.ts.map +1 -1
  46. package/dist/utils/unset.d.ts.map +1 -1
  47. package/package.json +21 -21
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/types/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpD,oBAAY,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjE,oBAAY,cAAc,CACxB,gBAAgB,SAAS,eAAe,GAAG,eAAe,IACxD,gBAAgB,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;AAEhE,oBAAY,sBAAsB,CAChC,gBAAgB,SAAS,eAAe,GAAG,eAAe,IACxD;IACF,KAAK,EAAE,gBAAgB,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,cAAc,GAAG,OAAO,GAAG,OAAO,EAAE,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvE,oBAAY,QAAQ,CAAC,WAAW,IAAI,CAClC,KAAK,EAAE,WAAW,KACf,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAE9C,oBAAY,eAAe,CACzB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,UAAU,SAAS,UAAU,GAAG,KAAK,IACnC,OAAO,CAAC;IACV,QAAQ,EAAE,OAAO,GAAG,cAAc,CAAC,OAAO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B,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;CAC/C,CAAC,CAAC"}
@@ -1,3 +1,27 @@
1
1
  import { FieldValues, PathString, UseControllerProps, UseControllerReturn } from './types';
2
+ /**
3
+ * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
4
+ *
5
+ * @remarks
6
+ * [API](https://react-hook-form.com/api/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
7
+ *
8
+ * @param props - the path name to the form field value, and validation rules.
9
+ *
10
+ * @returns field properties, field and form state. {@link UseControllerReturn}
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * function Input(props) {
15
+ * const { field, fieldState, formState } = useController(props);
16
+ * return (
17
+ * <div>
18
+ * <input {...field} placeholder={props.name} />
19
+ * <p>{fieldState.isTouched && "Touched"}</p>
20
+ * <p>{formState.isSubmitted ? "submitted" : ""}</p>
21
+ * </div>
22
+ * );
23
+ * }
24
+ * ```
25
+ */
2
26
  export declare function useController<TFieldValues extends FieldValues, TName extends PathString>(props: UseControllerProps<TFieldValues, TName>): UseControllerReturn<TFieldValues, TName>;
3
27
  //# sourceMappingURL=useController.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useController.d.ts","sourceRoot":"","sources":["../src/useController.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,WAAW,EAEX,UAAU,EAEV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAKjB,wBAAgB,aAAa,CAC3B,YAAY,SAAS,WAAW,EAChC,KAAK,SAAS,UAAU,EAExB,KAAK,EAAE,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,GAC7C,mBAAmB,CAAC,YAAY,EAAE,KAAK,CAAC,CA+F1C"}
1
+ {"version":3,"file":"useController.d.ts","sourceRoot":"","sources":["../src/useController.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,WAAW,EAEX,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAC3B,YAAY,SAAS,WAAW,EAChC,KAAK,SAAS,UAAU,EAExB,KAAK,EAAE,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,GAC7C,mBAAmB,CAAC,YAAY,EAAE,KAAK,CAAC,CA+F1C"}
@@ -1,3 +1,40 @@
1
- import { FieldValues, UseFieldArrayProps, UseFieldArrayReturn } from './types';
2
- export declare const useFieldArray: <TFieldValues extends FieldValues, TFieldArrayName extends string>(props: UseFieldArrayProps<TFieldValues, TFieldArrayName>) => UseFieldArrayReturn<TFieldValues, TFieldArrayName>;
1
+ import { FieldValues, PathString, UseFieldArrayProps, UseFieldArrayReturn } from './types';
2
+ /**
3
+ * A custom hook that exposes convenient methods to perform operations with a list of dynamic inputs that need to be appended, updated, removed etc.
4
+ *
5
+ * @remarks
6
+ * [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn)
7
+ *
8
+ * @param props - useFieldArray props
9
+ *
10
+ * @returns methods - functions to manipulate with the Field Arrays (dynamic inputs) {@link UseFieldArrayReturn}
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * function App() {
15
+ * const { register, control, handleSubmit, reset, trigger, setError } = useForm({
16
+ * defaultValues: {
17
+ * test: []
18
+ * }
19
+ * });
20
+ * const { fields, append } = useFieldArray({
21
+ * control,
22
+ * name: "test"
23
+ * });
24
+ *
25
+ * return (
26
+ * <form onSubmit={handleSubmit(data => console.log(data))}>
27
+ * {fields.map((item, index) => (
28
+ * <input key={item.id} {...register(`test.${index}.firstName`)} />
29
+ * ))}
30
+ * <button type="button" onClick={() => append({ firstName: "bill" })}>
31
+ * append
32
+ * </button>
33
+ * <input type="submit" />
34
+ * </form>
35
+ * );
36
+ * }
37
+ * ```
38
+ */
39
+ export declare function useFieldArray<TFieldValues extends FieldValues, TFieldArrayName extends PathString>(props: UseFieldArrayProps<TFieldValues, TFieldArrayName>): UseFieldArrayReturn<TFieldValues, TFieldArrayName>;
3
40
  //# sourceMappingURL=useFieldArray.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFieldArray.d.ts","sourceRoot":"","sources":["../src/useFieldArray.ts"],"names":[],"mappings":"AAkBA,OAAO,EAML,WAAW,EAEX,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAIjB,eAAO,MAAM,aAAa,oLA0QzB,CAAC"}
1
+ {"version":3,"file":"useFieldArray.d.ts","sourceRoot":"","sources":["../src/useFieldArray.ts"],"names":[],"mappings":"AAuBA,OAAO,EAOL,WAAW,EACX,UAAU,EAEV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,aAAa,CAC3B,YAAY,SAAS,WAAW,EAChC,eAAe,SAAS,UAAU,EAElC,KAAK,EAAE,kBAAkB,CAAC,YAAY,EAAE,eAAe,CAAC,GACvD,mBAAmB,CAAC,YAAY,EAAE,eAAe,CAAC,CA4SpD"}
package/dist/useForm.d.ts CHANGED
@@ -1,3 +1,32 @@
1
1
  import { FieldValues, UseFormProps, UseFormReturn } from './types';
2
- export declare function useForm<TFieldValues extends FieldValues = FieldValues, TContext extends object = object>(props?: UseFormProps<TFieldValues, TContext>): UseFormReturn<TFieldValues, TContext>;
2
+ /**
3
+ * Custom hook to mange the entire form.
4
+ *
5
+ * @remarks
6
+ * [API](https://react-hook-form.com/api/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}
11
+ *
12
+ * @example
13
+ * ```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
+ * <input type="submit" />
26
+ * </form>
27
+ * );
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function useForm<TFieldValues extends FieldValues = FieldValues, TContext = any>(props?: UseFormProps<TFieldValues, TContext>): UseFormReturn<TFieldValues, TContext>;
3
32
  //# sourceMappingURL=useForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,WAAW,EAEX,YAAY,EACZ,aAAa,EACd,MAAM,SAAS,CAAC;AAGjB,wBAAgB,OAAO,CACrB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,SAAS,MAAM,GAAG,MAAM,EAEhC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,CAAM,GAC/C,aAAa,CAAC,YAAY,EAAE,QAAQ,CAAC,CAiEvC"}
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,WAAW,EAEX,YAAY,EACZ,aAAa,EACd,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,OAAO,CACrB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EAEd,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,CAAM,GAC/C,aAAa,CAAC,YAAY,EAAE,QAAQ,CAAC,CAmEvC"}
@@ -1,4 +1,64 @@
1
1
  import { FieldValues, FormProviderProps, UseFormReturn } from './types';
2
- export declare const useFormContext: <TFieldValues extends FieldValues>() => UseFormReturn<TFieldValues, object>;
3
- export declare const FormProvider: <TFieldValues extends FieldValues, TContext extends object = object>(props: FormProviderProps<TFieldValues, TContext>) => JSX.Element;
2
+ /**
3
+ * 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
+ *
5
+ * @remarks
6
+ * [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
7
+ *
8
+ * @returns return all useForm methods
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * function App() {
13
+ * const methods = useForm();
14
+ * const onSubmit = data => console.log(data);
15
+ *
16
+ * return (
17
+ * <FormProvider {...methods} >
18
+ * <form onSubmit={methods.handleSubmit(onSubmit)}>
19
+ * <NestedInput />
20
+ * <input type="submit" />
21
+ * </form>
22
+ * </FormProvider>
23
+ * );
24
+ * }
25
+ *
26
+ * function NestedInput() {
27
+ * const { register } = useFormContext(); // retrieve all hook methods
28
+ * return <input {...register("test")} />;
29
+ * }
30
+ * ```
31
+ */
32
+ export declare const useFormContext: <TFieldValues extends FieldValues>() => UseFormReturn<TFieldValues, any>;
33
+ /**
34
+ * A provider component that propagates the `useForm` methods to all children components via [React Context](https://reactjs.org/docs/context.html) API. To be used with {@link useFormContext}.
35
+ *
36
+ * @remarks
37
+ * [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
38
+ *
39
+ * @param props - all useFrom methods
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * function App() {
44
+ * const methods = useForm();
45
+ * const onSubmit = data => console.log(data);
46
+ *
47
+ * return (
48
+ * <FormProvider {...methods} >
49
+ * <form onSubmit={methods.handleSubmit(onSubmit)}>
50
+ * <NestedInput />
51
+ * <input type="submit" />
52
+ * </form>
53
+ * </FormProvider>
54
+ * );
55
+ * }
56
+ *
57
+ * function NestedInput() {
58
+ * const { register } = useFormContext(); // retrieve all hook methods
59
+ * return <input {...register("test")} />;
60
+ * }
61
+ * ```
62
+ */
63
+ export declare const FormProvider: <TFieldValues extends FieldValues, TContext = any>(props: FormProviderProps<TFieldValues, TContext>) => JSX.Element;
4
64
  //# sourceMappingURL=useFormContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFormContext.d.ts","sourceRoot":"","sources":["../src/useFormContext.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE,eAAO,MAAM,cAAc,6EAGkD,CAAC;AAE9E,eAAO,MAAM,YAAY,uIAWxB,CAAC"}
1
+ {"version":3,"file":"useFormContext.d.ts","sourceRoot":"","sources":["../src/useFormContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,cAAc,0EAGkD,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,YAAY,qHASxB,CAAC"}
@@ -1,4 +1,34 @@
1
1
  import { FieldValues, PathString, UseFormStateProps, UseFormStateReturn } from './types';
2
+ /**
3
+ * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
4
+ *
5
+ * @remarks
6
+ * [API](https://react-hook-form.com/api/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
7
+ *
8
+ * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
9
+ *
10
+ * @example
11
+ * ```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
+ * }
30
+ * ```
31
+ */
2
32
  declare function useFormState<TFieldValues extends FieldValues, TFieldName extends PathString>(props?: UseFormStateProps<TFieldValues, TFieldName>): UseFormStateReturn<TFieldValues>;
3
33
  export { useFormState };
4
34
  //# sourceMappingURL=useFormState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFormState.d.ts","sourceRoot":"","sources":["../src/useFormState.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EAEX,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAIjB,iBAAS,YAAY,CACnB,YAAY,SAAS,WAAW,EAChC,UAAU,SAAS,UAAU,EAE7B,KAAK,CAAC,EAAE,iBAAiB,CAAC,YAAY,EAAE,UAAU,CAAC,GAClD,kBAAkB,CAAC,YAAY,CAAC,CAoDlC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"useFormState.d.ts","sourceRoot":"","sources":["../src/useFormState.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EAEX,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,iBAAS,YAAY,CACnB,YAAY,SAAS,WAAW,EAChC,UAAU,SAAS,UAAU,EAE7B,KAAK,CAAC,EAAE,iBAAiB,CAAC,YAAY,EAAE,UAAU,CAAC,GAClD,kBAAkB,CAAC,YAAY,CAAC,CAoDlC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,10 +1,51 @@
1
- import { Auto, Control, DeepPartialSkipArrayKey, FieldPathValue, FieldPathValues, FieldValues, PathString, UnpackNestedValue } from './types';
1
+ import { Auto, Control, DeepPartialSkipArrayKey, FieldPathValue, FieldPathValues, FieldValues, PathString } from './types';
2
+ /**
3
+ * Subscribe to the entire form values change and re-render at the hook level.
4
+ *
5
+ * @remarks
6
+ *
7
+ * [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
8
+ *
9
+ * @param props - defaultValue, disable subscription and match exact name.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const { watch } = useForm();
14
+ * const values = useWatch({
15
+ * control,
16
+ * defaultValue: {
17
+ * name: "data"
18
+ * },
19
+ * exact: false,
20
+ * })
21
+ * ```
22
+ */
2
23
  export declare function useWatch<TFieldValues extends FieldValues>(props: {
3
- defaultValue?: UnpackNestedValue<DeepPartialSkipArrayKey<TFieldValues>>;
24
+ defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
4
25
  control?: Control<TFieldValues>;
5
26
  disabled?: boolean;
6
27
  exact?: boolean;
7
- }): UnpackNestedValue<DeepPartialSkipArrayKey<TFieldValues>>;
28
+ }): DeepPartialSkipArrayKey<TFieldValues>;
29
+ /**
30
+ * Custom hook to subscribe to field change and isolate re-rendering at the component level.
31
+ *
32
+ * @remarks
33
+ *
34
+ * [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
35
+ *
36
+ * @param props - defaultValue, disable subscription and match exact name.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * const { watch } = useForm();
41
+ * const values = useWatch({
42
+ * control,
43
+ * name: "fieldA",
44
+ * defaultValue: "default value",
45
+ * exact: false,
46
+ * })
47
+ * ```
48
+ */
8
49
  export declare function useWatch<TFieldValues extends FieldValues, TFieldName extends PathString>(props: {
9
50
  name: Auto.FieldPath<TFieldValues, TFieldName>;
10
51
  defaultValue?: FieldPathValue<TFieldValues, TFieldName>;
@@ -12,9 +53,32 @@ export declare function useWatch<TFieldValues extends FieldValues, TFieldName ex
12
53
  disabled?: boolean;
13
54
  exact?: boolean;
14
55
  }): FieldPathValue<TFieldValues, TFieldName>;
56
+ /**
57
+ * Custom hook to subscribe to field change and isolate re-rendering at the component level.
58
+ *
59
+ * @remarks
60
+ *
61
+ * [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
62
+ *
63
+ * @param props - defaultValue, disable subscription and match exact name.
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * const { watch } = useForm();
68
+ * const values = useWatch({
69
+ * control,
70
+ * name: ["fieldA", "fieldB"],
71
+ * defaultValue: {
72
+ * fieldA: "data",
73
+ * fieldB: "data"
74
+ * },
75
+ * exact: false,
76
+ * })
77
+ * ```
78
+ */
15
79
  export declare function useWatch<TFieldValues extends FieldValues, TFieldNames extends readonly PathString[]>(props: {
16
80
  name: readonly [...Auto.FieldPaths<TFieldValues, TFieldNames>];
17
- defaultValue?: UnpackNestedValue<DeepPartialSkipArrayKey<TFieldValues>>;
81
+ defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
18
82
  control?: Control<TFieldValues>;
19
83
  disabled?: boolean;
20
84
  exact?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useWatch.d.ts","sourceRoot":"","sources":["../src/useWatch.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,WAAW,EAEX,UAAU,EACV,iBAAiB,EAElB,MAAM,SAAS,CAAC;AAIjB,wBAAgB,QAAQ,CAAC,YAAY,SAAS,WAAW,EAAE,KAAK,EAAE;IAChE,YAAY,CAAC,EAAE,iBAAi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,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../../src/utils/compact.ts"],"names":[],"mappings":";AAAA,wBAAkE"}
1
+ {"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../../src/utils/compact.ts"],"names":[],"mappings":";AAAA,wBACoD"}
@@ -1 +1 @@
1
- {"version":3,"file":"unset.d.ts","sourceRoot":"","sources":["../../src/utils/unset.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,OA0CtD"}
1
+ {"version":3,"file":"unset.d.ts","sourceRoot":"","sources":["../../src/utils/unset.ts"],"names":[],"mappings":"AA0BA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,OAsCtD"}
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": "8.0.0-alpha.0",
4
+ "version": "8.0.0-alpha.3",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.mjs",
7
7
  "umd:main": "dist/index.umd.js",
@@ -10,7 +10,7 @@
10
10
  "jsnext:main": "dist/index.esm.mjs",
11
11
  "source": "src/index.ts",
12
12
  "types": "dist/index.d.ts",
13
- "sideEffects": true,
13
+ "sideEffects": false,
14
14
  "files": [
15
15
  "dist",
16
16
  "dist/__tests__"
@@ -29,7 +29,7 @@
29
29
  "postbuild": "rimraf dist/__tests__ && node ./scripts/rollup/assert-esm-exports.mjs && node ./scripts/rollup/assert-cjs-exports.cjs",
30
30
  "build:modern": "rollup -c ./scripts/rollup/rollup.config.js",
31
31
  "build:esm": "rollup -c ./scripts/rollup/rollup.esm.config.js",
32
- "prettier:fix": "prettier --config .prettierrc --write \"**/*.{ts,tsx}\"",
32
+ "prettier:fix": "prettier --config .prettierrc --write \"**/*.{ts,tsx,css}\"",
33
33
  "lint": "eslint '**/*.{js,ts,tsx}'",
34
34
  "lint:fix": "yarn lint -- --fix",
35
35
  "type": "tsc --noEmit",
@@ -70,45 +70,45 @@
70
70
  "license": "MIT",
71
71
  "devDependencies": {
72
72
  "@microsoft/api-extractor": "^7.19.4",
73
- "@rollup/plugin-commonjs": "^21.0.1",
73
+ "@rollup/plugin-commonjs": "^21.0.2",
74
74
  "@rollup/plugin-node-resolve": "^13.1.3",
75
- "@testing-library/jest-dom": "^5.16.1",
75
+ "@testing-library/jest-dom": "^5.16.2",
76
76
  "@testing-library/react": "13.0.0-alpha.5",
77
77
  "@testing-library/react-hooks": "8.0.0-alpha.1",
78
78
  "@testing-library/react-native": "^9.0.0",
79
- "@types/jest": "^27.4.0",
80
- "@types/react": "^17.0.38",
81
- "@types/react-native": "^0.66.15",
82
- "@typescript-eslint/eslint-plugin": "^5.10.0",
83
- "@typescript-eslint/parser": "^5.10.0",
79
+ "@types/jest": "^27.4.1",
80
+ "@types/react": "^17.0.40",
81
+ "@types/react-native": "^0.67.2",
82
+ "@typescript-eslint/eslint-plugin": "^5.14.0",
83
+ "@typescript-eslint/parser": "^5.14.0",
84
84
  "@vitejs/plugin-react-refresh": "^1.3.6",
85
- "babel-jest": "^27.4.6",
85
+ "babel-jest": "^27.5.1",
86
86
  "bundlesize": "^0.18.0",
87
- "cypress": "9.3.1",
88
- "eslint": "^8.7.0",
89
- "eslint-config-prettier": "^8.3.0",
87
+ "cypress": "9.4.1",
88
+ "eslint": "^8.11.0",
89
+ "eslint-config-prettier": "^8.5.0",
90
90
  "eslint-plugin-cypress": "^2.12.1",
91
91
  "eslint-plugin-prettier": "^4.0.0",
92
- "eslint-plugin-react": "^7.28.0",
92
+ "eslint-plugin-react": "^7.29.3",
93
93
  "eslint-plugin-react-hooks": "^4.3.0",
94
94
  "eslint-plugin-simple-import-sort": "^7.0.0",
95
95
  "husky": "^7.0.4",
96
- "jest": "^27.4.7",
97
- "lint-staged": "^12.2.2",
96
+ "jest": "^27.5.1",
97
+ "lint-staged": "^12.3.5",
98
98
  "prettier": "^2.5.1",
99
99
  "react": "18.0.0-rc.0-next-f2a59df48-20211208",
100
100
  "react-dom": "18.0.0-rc.0-next-f2a59df48-20211208",
101
- "react-native": "^0.67.1",
101
+ "react-native": "^0.67.3",
102
102
  "react-test-renderer": "18.0.0-rc.0-next-f2a59df48-20211208",
103
103
  "rimraf": "^3.0.2",
104
- "rollup": "^2.66.0",
104
+ "rollup": "^2.70.0",
105
105
  "rollup-plugin-peer-deps-external": "^2.2.4",
106
106
  "rollup-plugin-sourcemaps": "^0.6.2",
107
107
  "rollup-plugin-terser": "^7.0.2",
108
- "rollup-plugin-typescript2": "^0.31.1",
108
+ "rollup-plugin-typescript2": "^0.31.2",
109
109
  "ts-jest": "^27.1.3",
110
110
  "tsd": "^0.19.1",
111
- "typescript": "^4.5.5"
111
+ "typescript": "^4.6.2"
112
112
  },
113
113
  "bundlesize": [
114
114
  {