react-hook-form 7.55.0-next.3 → 7.55.0-next.5
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/README.md +12 -4
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +13 -10
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +9 -7
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useWatch.d.ts.map +1 -1
- package/package.json +13 -13
package/dist/index.esm.mjs
CHANGED
@@ -314,6 +314,7 @@ function useWatch(props) {
|
|
314
314
|
const methods = useFormContext();
|
315
315
|
const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
|
316
316
|
const _name = React.useRef(name);
|
317
|
+
const _defaultValue = React.useRef(defaultValue);
|
317
318
|
_name.current = name;
|
318
319
|
React.useEffect(() => control._subscribe({
|
319
320
|
name: _name.current,
|
@@ -322,8 +323,8 @@ function useWatch(props) {
|
|
322
323
|
},
|
323
324
|
exact,
|
324
325
|
callback: (formState) => !disabled &&
|
325
|
-
updateValue(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false,
|
326
|
-
}), [control,
|
326
|
+
updateValue(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, _defaultValue.current)),
|
327
|
+
}), [control, disabled, exact]);
|
327
328
|
const [value, updateValue] = React.useState(control._getWatch(name, defaultValue));
|
328
329
|
React.useEffect(() => control._removeUnmounted());
|
329
330
|
return value;
|
@@ -1695,8 +1696,10 @@ function createFormControl(props = {}) {
|
|
1695
1696
|
});
|
1696
1697
|
if (shouldSkipValidation) {
|
1697
1698
|
if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
|
1698
|
-
if (_options.mode === 'onBlur'
|
1699
|
-
|
1699
|
+
if (_options.mode === 'onBlur') {
|
1700
|
+
if (isBlurEvent) {
|
1701
|
+
_setValid();
|
1702
|
+
}
|
1700
1703
|
}
|
1701
1704
|
else if (!isBlurEvent) {
|
1702
1705
|
_setValid();
|
@@ -1994,11 +1997,6 @@ function createFormControl(props = {}) {
|
|
1994
1997
|
e.persist && e.persist();
|
1995
1998
|
}
|
1996
1999
|
let fieldValues = cloneObject(_formValues);
|
1997
|
-
if (_names.disabled.size) {
|
1998
|
-
for (const name of _names.disabled) {
|
1999
|
-
set(fieldValues, name, undefined);
|
2000
|
-
}
|
2001
|
-
}
|
2002
2000
|
_subjects.state.next({
|
2003
2001
|
isSubmitting: true,
|
2004
2002
|
});
|
@@ -2010,6 +2008,11 @@ function createFormControl(props = {}) {
|
|
2010
2008
|
else {
|
2011
2009
|
await executeBuiltInValidation(_fields);
|
2012
2010
|
}
|
2011
|
+
if (_names.disabled.size) {
|
2012
|
+
for (const name of _names.disabled) {
|
2013
|
+
set(fieldValues, name, undefined);
|
2014
|
+
}
|
2015
|
+
}
|
2013
2016
|
unset(_formState.errors, 'root');
|
2014
2017
|
if (isEmptyObject(_formState.errors)) {
|
2015
2018
|
_subjects.state.next({
|
@@ -2656,7 +2659,7 @@ function useForm(props = {}) {
|
|
2656
2659
|
}
|
2657
2660
|
}, [props.values, control]);
|
2658
2661
|
React.useEffect(() => {
|
2659
|
-
if (props.errors) {
|
2662
|
+
if (props.errors && !isEmptyObject(props.errors)) {
|
2660
2663
|
control._setErrors(props.errors);
|
2661
2664
|
}
|
2662
2665
|
}, [props.errors, control]);
|