react-hook-form 7.63.0 → 7.65.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.
package/dist/index.d.ts CHANGED
@@ -9,4 +9,5 @@ export * from './useFormContext';
9
9
  export * from './useFormState';
10
10
  export * from './useWatch';
11
11
  export * from './utils';
12
+ export * from './watch';
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -507,7 +507,7 @@ function useController(props) {
507
507
  };
508
508
  updateMounted(name, true);
509
509
  if (_shouldUnregisterField) {
510
- const value = cloneObject(get(control._options.defaultValues, name));
510
+ const value = cloneObject(get(control._options.defaultValues, name, _props.current.defaultValue));
511
511
  set(control._defaultValues, name, value);
512
512
  if (isUndefined(get(control._formValues, name))) {
513
513
  set(control._formValues, name, value);
@@ -834,7 +834,7 @@ function markFieldsDirty(data, fields = {}) {
834
834
  fields[key] = Array.isArray(data[key]) ? [] : {};
835
835
  markFieldsDirty(data[key], fields[key]);
836
836
  }
837
- else if (!isNullOrUndefined(data[key])) {
837
+ else if (!isUndefined(data[key])) {
838
838
  fields[key] = true;
839
839
  }
840
840
  }
@@ -2460,12 +2460,11 @@ function useFieldArray(props) {
2460
2460
  const { control = methods.control, name, keyName = 'id', shouldUnregister, rules, } = props;
2461
2461
  const [fields, setFields] = React.useState(control._getFieldArray(name));
2462
2462
  const ids = React.useRef(control._getFieldArray(name).map(generateId));
2463
- const _fieldIds = React.useRef(fields);
2464
2463
  const _actioned = React.useRef(false);
2465
- _fieldIds.current = fields;
2466
2464
  control._names.array.add(name);
2467
2465
  React.useMemo(() => rules &&
2468
- control.register(name, rules), [control, rules, name]);
2466
+ fields.length >= 0 &&
2467
+ control.register(name, rules), [control, name, fields.length, rules]);
2469
2468
  useIsomorphicLayoutEffect(() => control._subjects.array.subscribe({
2470
2469
  next: ({ values, name: fieldArrayName, }) => {
2471
2470
  if (fieldArrayName === name || !fieldArrayName) {
@@ -2799,5 +2798,29 @@ function useForm(props = {}) {
2799
2798
  return _formControl.current;
2800
2799
  }
2801
2800
 
2802
- export { Controller, Form, FormProvider, appendErrors, createFormControl, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2801
+ /**
2802
+ * Watch component that subscribes to form field changes and re-renders when watched fields update.
2803
+ *
2804
+ * @param control - The form control object from useForm
2805
+ * @param names - Array of field names to watch for changes
2806
+ * @param render - The function that receives watched values and returns ReactNode
2807
+ * @returns The result of calling render function with watched values
2808
+ *
2809
+ * @example
2810
+ * The `Watch` component only re-render when the values of `foo`, `bar`, and `baz.qux` change.
2811
+ * The types of `foo`, `bar`, and `baz.qux` are precisely inferred.
2812
+ *
2813
+ * ```tsx
2814
+ * const { control } = useForm();
2815
+ *
2816
+ * <Watch
2817
+ * control={control}
2818
+ * names={['foo', 'bar', 'baz.qux']}
2819
+ * render={([foo, bar, baz_qux]) => <div>{foo}{bar}{baz_qux}</div>}
2820
+ * />
2821
+ * ```
2822
+ */
2823
+ const Watch = ({ control, names, render, }) => render(useWatch({ control, name: names }));
2824
+
2825
+ export { Controller, Form, FormProvider, Watch, appendErrors, createFormControl, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2803
2826
  //# sourceMappingURL=index.esm.mjs.map