react-hook-form 7.56.1 → 7.56.3
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 +3 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +41 -48
- 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/react-server.esm.mjs +1 -1
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useIsomorphicLayoutEffect.d.ts +3 -0
- package/dist/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/useDeepEqualEffect.d.ts +0 -3
- package/dist/useDeepEqualEffect.d.ts.map +0 -1
package/dist/index.esm.mjs
CHANGED
@@ -217,47 +217,7 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
|
|
217
217
|
return result;
|
218
218
|
};
|
219
219
|
|
220
|
-
|
221
|
-
|
222
|
-
function deepEqual(object1, object2) {
|
223
|
-
if (isPrimitive(object1) || isPrimitive(object2)) {
|
224
|
-
return object1 === object2;
|
225
|
-
}
|
226
|
-
if (isDateObject(object1) && isDateObject(object2)) {
|
227
|
-
return object1.getTime() === object2.getTime();
|
228
|
-
}
|
229
|
-
const keys1 = Object.keys(object1);
|
230
|
-
const keys2 = Object.keys(object2);
|
231
|
-
if (keys1.length !== keys2.length) {
|
232
|
-
return false;
|
233
|
-
}
|
234
|
-
for (const key of keys1) {
|
235
|
-
const val1 = object1[key];
|
236
|
-
if (!keys2.includes(key)) {
|
237
|
-
return false;
|
238
|
-
}
|
239
|
-
if (key !== 'ref') {
|
240
|
-
const val2 = object2[key];
|
241
|
-
if ((isDateObject(val1) && isDateObject(val2)) ||
|
242
|
-
(isObject(val1) && isObject(val2)) ||
|
243
|
-
(Array.isArray(val1) && Array.isArray(val2))
|
244
|
-
? !deepEqual(val1, val2)
|
245
|
-
: val1 !== val2) {
|
246
|
-
return false;
|
247
|
-
}
|
248
|
-
}
|
249
|
-
}
|
250
|
-
return true;
|
251
|
-
}
|
252
|
-
|
253
|
-
const useDeepEqualEffect = (effect, deps) => {
|
254
|
-
const ref = React.useRef(deps);
|
255
|
-
if (!deepEqual(deps, ref.current)) {
|
256
|
-
ref.current = deps;
|
257
|
-
}
|
258
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
259
|
-
React.useEffect(effect, ref.current);
|
260
|
-
};
|
220
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
261
221
|
|
262
222
|
/**
|
263
223
|
* This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
|
@@ -303,7 +263,7 @@ function useFormState(props) {
|
|
303
263
|
isValid: false,
|
304
264
|
errors: false,
|
305
265
|
});
|
306
|
-
|
266
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
307
267
|
name: name,
|
308
268
|
formState: _localProxyFormState.current,
|
309
269
|
exact,
|
@@ -354,16 +314,17 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
|
|
354
314
|
function useWatch(props) {
|
355
315
|
const methods = useFormContext();
|
356
316
|
const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
|
357
|
-
const
|
358
|
-
|
317
|
+
const _defaultValue = React__default.useRef(defaultValue);
|
318
|
+
const [value, updateValue] = React__default.useState(control._getWatch(name, _defaultValue.current));
|
319
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
359
320
|
name: name,
|
360
321
|
formState: {
|
361
322
|
values: true,
|
362
323
|
},
|
363
324
|
exact,
|
364
325
|
callback: (formState) => !disabled &&
|
365
|
-
updateValue(generateWatchOutput(name, control._names, formState.values || control._formValues, false,
|
366
|
-
}), [name,
|
326
|
+
updateValue(generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current)),
|
327
|
+
}), [name, control, disabled, exact]);
|
367
328
|
React__default.useEffect(() => control._removeUnmounted());
|
368
329
|
return value;
|
369
330
|
}
|
@@ -713,6 +674,39 @@ var createSubject = () => {
|
|
713
674
|
};
|
714
675
|
};
|
715
676
|
|
677
|
+
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
678
|
+
|
679
|
+
function deepEqual(object1, object2) {
|
680
|
+
if (isPrimitive(object1) || isPrimitive(object2)) {
|
681
|
+
return object1 === object2;
|
682
|
+
}
|
683
|
+
if (isDateObject(object1) && isDateObject(object2)) {
|
684
|
+
return object1.getTime() === object2.getTime();
|
685
|
+
}
|
686
|
+
const keys1 = Object.keys(object1);
|
687
|
+
const keys2 = Object.keys(object2);
|
688
|
+
if (keys1.length !== keys2.length) {
|
689
|
+
return false;
|
690
|
+
}
|
691
|
+
for (const key of keys1) {
|
692
|
+
const val1 = object1[key];
|
693
|
+
if (!keys2.includes(key)) {
|
694
|
+
return false;
|
695
|
+
}
|
696
|
+
if (key !== 'ref') {
|
697
|
+
const val2 = object2[key];
|
698
|
+
if ((isDateObject(val1) && isDateObject(val2)) ||
|
699
|
+
(isObject(val1) && isObject(val2)) ||
|
700
|
+
(Array.isArray(val1) && Array.isArray(val2))
|
701
|
+
? !deepEqual(val1, val2)
|
702
|
+
: val1 !== val2) {
|
703
|
+
return false;
|
704
|
+
}
|
705
|
+
}
|
706
|
+
}
|
707
|
+
return true;
|
708
|
+
}
|
709
|
+
|
716
710
|
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
717
711
|
|
718
712
|
var isFileInput = (element) => element.type === 'file';
|
@@ -1276,7 +1270,7 @@ function createFormControl(props = {}) {
|
|
1276
1270
|
};
|
1277
1271
|
const _fields = {};
|
1278
1272
|
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
|
1279
|
-
? cloneObject(_options.
|
1273
|
+
? cloneObject(_options.defaultValues || _options.values) || {}
|
1280
1274
|
: {};
|
1281
1275
|
let _formValues = _options.shouldUnregister
|
1282
1276
|
? {}
|
@@ -2587,7 +2581,6 @@ function useFieldArray(props) {
|
|
2587
2581
|
};
|
2588
2582
|
}
|
2589
2583
|
|
2590
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__default.useLayoutEffect : React__default.useEffect;
|
2591
2584
|
/**
|
2592
2585
|
* Custom hook to manage the entire form.
|
2593
2586
|
*
|