react-hook-form 7.12.1 → 7.12.2
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.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +28 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/utils/deepEqual.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
@@ -301,29 +301,30 @@ var mapIds = (values = [], keyName) => values.map((value) => (Object.assign({ [k
|
|
301
301
|
|
302
302
|
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
303
303
|
|
304
|
-
function deepEqual(object1, object2
|
304
|
+
function deepEqual(object1, object2) {
|
305
305
|
if (isPrimitive(object1) ||
|
306
306
|
isPrimitive(object2) ||
|
307
307
|
isDateObject(object1) ||
|
308
308
|
isDateObject(object2)) {
|
309
309
|
return object1 === object2;
|
310
310
|
}
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
311
|
+
const keys1 = Object.keys(object1);
|
312
|
+
const keys2 = Object.keys(object2);
|
313
|
+
if (keys1.length !== keys2.length) {
|
314
|
+
return false;
|
315
|
+
}
|
316
|
+
for (const key of keys1) {
|
317
|
+
const val1 = object1[key];
|
318
|
+
if (!keys2.includes(key)) {
|
315
319
|
return false;
|
316
320
|
}
|
317
|
-
|
318
|
-
const
|
319
|
-
if (
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
: val1 !== val2) {
|
325
|
-
return false;
|
326
|
-
}
|
321
|
+
if (key !== 'ref') {
|
322
|
+
const val2 = object2[key];
|
323
|
+
if ((isObject(val1) || Array.isArray(val1)) &&
|
324
|
+
(isObject(val2) || Array.isArray(val2))
|
325
|
+
? !deepEqual(val1, val2)
|
326
|
+
: val1 !== val2) {
|
327
|
+
return false;
|
327
328
|
}
|
328
329
|
}
|
329
330
|
}
|
@@ -1067,12 +1068,21 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
1067
1068
|
errors: formStateRef.current.errors,
|
1068
1069
|
});
|
1069
1070
|
};
|
1071
|
+
const shouldRenderBaseOnValid = async () => {
|
1072
|
+
const isValid = await validateForm(fieldsRef.current, true);
|
1073
|
+
if (isValid !== formStateRef.current.isValid) {
|
1074
|
+
formStateRef.current.isValid = isValid;
|
1075
|
+
subjectsRef.current.state.next({
|
1076
|
+
isValid,
|
1077
|
+
});
|
1078
|
+
}
|
1079
|
+
};
|
1070
1080
|
const shouldRenderBaseOnError = React.useCallback(async (shouldSkipRender, name, error, fieldState, isValidFromResolver, isWatched) => {
|
1071
1081
|
const previousError = get(formStateRef.current.errors, name);
|
1072
1082
|
const isValid = readFormStateRef.current.isValid
|
1073
1083
|
? resolver
|
1074
1084
|
? isValidFromResolver
|
1075
|
-
:
|
1085
|
+
: shouldRenderBaseOnValid()
|
1076
1086
|
: false;
|
1077
1087
|
if (delayError && error) {
|
1078
1088
|
_delayCallback.current =
|
@@ -1085,11 +1095,11 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
1085
1095
|
: unset(formStateRef.current.errors, name);
|
1086
1096
|
}
|
1087
1097
|
if ((isWatched ||
|
1088
|
-
(error ? !deepEqual(previousError, error
|
1098
|
+
(error ? !deepEqual(previousError, error) : previousError) ||
|
1089
1099
|
!isEmptyObject(fieldState) ||
|
1090
1100
|
formStateRef.current.isValid !== isValid) &&
|
1091
1101
|
!shouldSkipRender) {
|
1092
|
-
const updatedFormState = Object.assign(Object.assign({}, fieldState), { isValid: !!isValid, errors: formStateRef.current.errors, name });
|
1102
|
+
const updatedFormState = Object.assign(Object.assign(Object.assign({}, fieldState), (resolver ? { isValid: !!isValid } : {})), { errors: formStateRef.current.errors, name });
|
1093
1103
|
formStateRef.current = Object.assign(Object.assign({}, formStateRef.current), updatedFormState);
|
1094
1104
|
subjectsRef.current.state.next(isWatched ? { name } : updatedFormState);
|
1095
1105
|
}
|