react-hook-form 7.66.1 → 7.68.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
@@ -1,5 +1,6 @@
1
1
  export * from './controller';
2
2
  export * from './form';
3
+ export * from './formStateSubscribe';
3
4
  export * from './logic';
4
5
  export * from './types';
5
6
  export * from './useController';
@@ -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;AACxB,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,sBAAsB,CAAC;AACrC,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"}
@@ -443,19 +443,19 @@ function useWatch(props) {
443
443
  */
444
444
  function useController(props) {
445
445
  const methods = useFormContext();
446
- const { name, disabled, control = methods.control, shouldUnregister, defaultValue, } = props;
446
+ const { name, disabled, control = methods.control, shouldUnregister, defaultValue, exact = true, } = props;
447
447
  const isArrayField = isNameInFieldArray(control._names.array, name);
448
448
  const defaultValueMemo = React.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
449
449
  const value = useWatch({
450
450
  control,
451
451
  name,
452
452
  defaultValue: defaultValueMemo,
453
- exact: true,
453
+ exact,
454
454
  });
455
455
  const formState = useFormState({
456
456
  control,
457
457
  name,
458
- exact: true,
458
+ exact,
459
459
  });
460
460
  const _props = React.useRef(props);
461
461
  const _previousNameRef = React.useRef(undefined);
@@ -732,6 +732,8 @@ function Form(props) {
732
732
  }))) : (React.createElement("form", { noValidate: mounted, action: action, method: method, encType: encType, onSubmit: submit, ...rest }, children));
733
733
  }
734
734
 
735
+ const FormStateSubscribe = ({ control, disabled, exact, name, render, }) => render(useFormState({ control, name, disabled, exact }));
736
+
735
737
  var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
736
738
  ? {
737
739
  ...errors[name],
@@ -2244,6 +2246,13 @@ function createFormControl(props = {}) {
2244
2246
  !!keepStateOptions.keepDirtyValues ||
2245
2247
  (!_options.shouldUnregister && !isEmptyObject(values));
2246
2248
  _state.watch = !!_options.shouldUnregister;
2249
+ _state.action = false;
2250
+ // Clear errors synchronously to prevent validation errors on subsequent submissions
2251
+ // This fixes the issue where form.reset() causes validation errors on subsequent
2252
+ // submissions in Next.js 16 with Server Actions
2253
+ if (!keepStateOptions.keepErrors) {
2254
+ _formState.errors = {};
2255
+ }
2247
2256
  _subjects.state.next({
2248
2257
  submitCount: keepStateOptions.keepSubmitCount
2249
2258
  ? _formState.submitCount
@@ -2865,5 +2874,5 @@ function useForm(props = {}) {
2865
2874
  */
2866
2875
  const Watch = ({ control, names, render, }) => render(useWatch({ control, name: names }));
2867
2876
 
2868
- export { Controller, Form, FormProvider, Watch, appendErrors, createFormControl, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2877
+ export { Controller, Form, FormProvider, FormStateSubscribe, Watch, appendErrors, createFormControl, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2869
2878
  //# sourceMappingURL=index.esm.mjs.map