@bombillazo/rhf-plus 7.64.0-plus.2 → 7.65.0-plus.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"}
@@ -976,7 +976,7 @@ function markFieldsDirty(data, fields = {}) {
976
976
  fields[key] = Array.isArray(data[key]) ? [] : {};
977
977
  markFieldsDirty(data[key], fields[key]);
978
978
  }
979
- else if (!isNullOrUndefined(data[key])) {
979
+ else if (!isUndefined(data[key])) {
980
980
  fields[key] = true;
981
981
  }
982
982
  }
@@ -2892,7 +2892,8 @@ function useFieldArray(props) {
2892
2892
  const _actioned = React.useRef(false);
2893
2893
  control._names.array.add(name);
2894
2894
  React.useMemo(() => rules &&
2895
- control.register(name, rules), [control, rules, name]);
2895
+ fields.length >= 0 &&
2896
+ control.register(name, rules), [control, name, fields.length, rules]);
2896
2897
  useIsomorphicLayoutEffect(() => control._subjects.array.subscribe({
2897
2898
  next: ({ values, name: fieldArrayName, }) => {
2898
2899
  if (fieldArrayName === name || !fieldArrayName) {
@@ -3255,5 +3256,29 @@ function useForm(props = {}) {
3255
3256
  return _formControl.current;
3256
3257
  }
3257
3258
 
3258
- export { Controller, Form, FormProvider, appendErrors, createFormControl, get, set, submitForm as submit, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
3259
+ /**
3260
+ * Watch component that subscribes to form field changes and re-renders when watched fields update.
3261
+ *
3262
+ * @param control - The form control object from useForm
3263
+ * @param names - Array of field names to watch for changes
3264
+ * @param render - The function that receives watched values and returns ReactNode
3265
+ * @returns The result of calling render function with watched values
3266
+ *
3267
+ * @example
3268
+ * The `Watch` component only re-render when the values of `foo`, `bar`, and `baz.qux` change.
3269
+ * The types of `foo`, `bar`, and `baz.qux` are precisely inferred.
3270
+ *
3271
+ * ```tsx
3272
+ * const { control } = useForm();
3273
+ *
3274
+ * <Watch
3275
+ * control={control}
3276
+ * names={['foo', 'bar', 'baz.qux']}
3277
+ * render={([foo, bar, baz_qux]) => <div>{foo}{bar}{baz_qux}</div>}
3278
+ * />
3279
+ * ```
3280
+ */
3281
+ const Watch = ({ control, names, render, }) => render(useWatch({ control, name: names }));
3282
+
3283
+ export { Controller, Form, FormProvider, Watch, appendErrors, createFormControl, get, set, submitForm as submit, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
3259
3284
  //# sourceMappingURL=index.esm.mjs.map