react-hook-form 7.77.0 → 7.78.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/README.md +0 -11
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +32 -14
- 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 +13 -6
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/utils/deepEqual.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.mjs
CHANGED
|
@@ -248,6 +248,7 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
|
|
|
248
248
|
|
|
249
249
|
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
250
250
|
|
|
251
|
+
const isEmptyObjectWithCustomPrototype = (object, keys) => keys.length === 0 && !Array.isArray(object) && !isPlainObject(object);
|
|
251
252
|
function deepEqual(object1, object2, visited = new WeakSet()) {
|
|
252
253
|
if (object1 === object2) {
|
|
253
254
|
return true;
|
|
@@ -263,6 +264,10 @@ function deepEqual(object1, object2, visited = new WeakSet()) {
|
|
|
263
264
|
if (keys1.length !== keys2.length) {
|
|
264
265
|
return false;
|
|
265
266
|
}
|
|
267
|
+
if (isEmptyObjectWithCustomPrototype(object1, keys1) ||
|
|
268
|
+
isEmptyObjectWithCustomPrototype(object2, keys2)) {
|
|
269
|
+
return Object.is(object1, object2);
|
|
270
|
+
}
|
|
266
271
|
if (visited.has(object1) || visited.has(object2)) {
|
|
267
272
|
return true;
|
|
268
273
|
}
|
|
@@ -442,13 +447,22 @@ function useController(props) {
|
|
|
442
447
|
get: () => get(formState.errors, name),
|
|
443
448
|
},
|
|
444
449
|
}), [formState, name]);
|
|
445
|
-
const onChange = React.useCallback((event) =>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
450
|
+
const onChange = React.useCallback((event) => {
|
|
451
|
+
const value = getEventValue(event);
|
|
452
|
+
if (!get(control._fields, name)) {
|
|
453
|
+
_registerProps.current = control.register(name, {
|
|
454
|
+
..._props.current.rules,
|
|
455
|
+
value,
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
_registerProps.current.onChange({
|
|
459
|
+
target: {
|
|
460
|
+
value: getEventValue(event),
|
|
461
|
+
name: name,
|
|
462
|
+
},
|
|
463
|
+
type: EVENTS.CHANGE,
|
|
464
|
+
});
|
|
465
|
+
}, [name, control]);
|
|
452
466
|
const onBlur = React.useCallback(() => _registerProps.current.onBlur({
|
|
453
467
|
target: {
|
|
454
468
|
value: get(control._formValues, name),
|
|
@@ -493,7 +507,9 @@ function useController(props) {
|
|
|
493
507
|
};
|
|
494
508
|
updateMounted(name, true);
|
|
495
509
|
if (_shouldUnregisterField) {
|
|
496
|
-
const value = cloneObject(get(
|
|
510
|
+
const value = cloneObject(get(shouldUnregister
|
|
511
|
+
? control._defaultValues
|
|
512
|
+
: control._options.values || control._defaultValues, name, get(control._options.defaultValues, name, _props.current.defaultValue)));
|
|
497
513
|
set(control._defaultValues, name, value);
|
|
498
514
|
if (isUndefined(get(control._formValues, name))) {
|
|
499
515
|
set(control._formValues, name, value);
|
|
@@ -2080,13 +2096,15 @@ function createFormControl(props = {}) {
|
|
|
2080
2096
|
const { errors } = await _runSchema([name]);
|
|
2081
2097
|
_updateIsValidating([name]);
|
|
2082
2098
|
_updateIsFieldValueUpdated(fieldValue);
|
|
2083
|
-
if (isFieldValueUpdated) {
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
error = errorLookupResult.error;
|
|
2087
|
-
name = errorLookupResult.name;
|
|
2088
|
-
isValid = isEmptyObject(errors);
|
|
2099
|
+
if (!isFieldValueUpdated) {
|
|
2100
|
+
!isEmptyObject(fieldState) && _subjects.state.next(fieldState);
|
|
2101
|
+
return;
|
|
2089
2102
|
}
|
|
2103
|
+
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
2104
|
+
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
|
2105
|
+
error = errorLookupResult.error;
|
|
2106
|
+
name = errorLookupResult.name;
|
|
2107
|
+
isValid = isEmptyObject(errors);
|
|
2090
2108
|
}
|
|
2091
2109
|
else {
|
|
2092
2110
|
_updateIsValidating([name], true);
|