react-hook-form 7.55.0-next.0 → 7.55.0-next.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.
@@ -396,45 +396,41 @@ function useController(props) {
396
396
  get: () => get(formState.errors, name),
397
397
  },
398
398
  }), [formState, name]);
399
+ const onChange = React.useCallback((event) => _registerProps.current.onChange({
400
+ target: {
401
+ value: getEventValue(event),
402
+ name: name,
403
+ },
404
+ type: EVENTS.CHANGE,
405
+ }), [name]);
406
+ const onBlur = React.useCallback(() => _registerProps.current.onBlur({
407
+ target: {
408
+ value: get(control._formValues, name),
409
+ name: name,
410
+ },
411
+ type: EVENTS.BLUR,
412
+ }), [name, control._formValues]);
413
+ const ref = React.useCallback((elm) => {
414
+ const field = get(control._fields, name);
415
+ if (field && elm) {
416
+ field._f.ref = {
417
+ focus: () => elm.focus(),
418
+ select: () => elm.select(),
419
+ setCustomValidity: (message) => elm.setCustomValidity(message),
420
+ reportValidity: () => elm.reportValidity(),
421
+ };
422
+ }
423
+ }, [control._fields, name]);
399
424
  const field = React.useMemo(() => ({
400
425
  name,
401
426
  value,
402
427
  ...(isBoolean(disabled) || formState.disabled
403
428
  ? { disabled: formState.disabled || disabled }
404
429
  : {}),
405
- onChange: (event) => _registerProps.current.onChange({
406
- target: {
407
- value: getEventValue(event),
408
- name: name,
409
- },
410
- type: EVENTS.CHANGE,
411
- }),
412
- onBlur: () => _registerProps.current.onBlur({
413
- target: {
414
- value: get(control._formValues, name),
415
- name: name,
416
- },
417
- type: EVENTS.BLUR,
418
- }),
419
- ref: (elm) => {
420
- const field = get(control._fields, name);
421
- if (field && elm) {
422
- field._f.ref = {
423
- focus: () => elm.focus(),
424
- select: () => elm.select(),
425
- setCustomValidity: (message) => elm.setCustomValidity(message),
426
- reportValidity: () => elm.reportValidity(),
427
- };
428
- }
429
- },
430
- }), [
431
- name,
432
- control._formValues,
433
- disabled,
434
- formState.disabled,
435
- value,
436
- control._fields,
437
- ]);
430
+ onChange,
431
+ onBlur,
432
+ ref,
433
+ }), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
438
434
  React.useEffect(() => {
439
435
  const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
440
436
  const updateMounted = (name, value) => {
@@ -463,7 +459,6 @@ function useController(props) {
463
459
  React.useEffect(() => {
464
460
  control._setDisabledField({
465
461
  disabled,
466
- fields: control._fields,
467
462
  name,
468
463
  });
469
464
  }, [disabled, name, control]);
@@ -1411,18 +1406,15 @@ function createFormControl(props = {}) {
1411
1406
  name,
1412
1407
  };
1413
1408
  if (!_options.disabled) {
1414
- const disabledField = !!(get(_fields, name) &&
1415
- get(_fields, name)._f &&
1416
- get(_fields, name)._f.disabled);
1417
1409
  if (!isBlurEvent || shouldDirty) {
1418
1410
  if (_proxyFormState.isDirty || _proxySubscribeFormState.isDirty) {
1419
1411
  isPreviousDirty = _formState.isDirty;
1420
1412
  _formState.isDirty = output.isDirty = _getDirty();
1421
1413
  shouldUpdateField = isPreviousDirty !== output.isDirty;
1422
1414
  }
1423
- const isCurrentFieldPristine = disabledField || deepEqual(get(_defaultValues, name), fieldValue);
1424
- isPreviousDirty = !!(!disabledField && get(_formState.dirtyFields, name));
1425
- isCurrentFieldPristine || disabledField
1415
+ const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1416
+ isPreviousDirty = !!get(_formState.dirtyFields, name);
1417
+ isCurrentFieldPristine
1426
1418
  ? unset(_formState.dirtyFields, name)
1427
1419
  : set(_formState.dirtyFields, name, true);
1428
1420
  output.dirtyFields = _formState.dirtyFields;
@@ -1878,12 +1870,11 @@ function createFormControl(props = {}) {
1878
1870
  });
1879
1871
  !options.keepIsValid && _setValid();
1880
1872
  };
1881
- const _setDisabledField = ({ disabled, name, field, fields, }) => {
1873
+ const _setDisabledField = ({ disabled, name, }) => {
1882
1874
  if ((isBoolean(disabled) && _state.mount) ||
1883
1875
  !!disabled ||
1884
1876
  _names.disabled.has(name)) {
1885
1877
  disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
1886
- updateTouchAndDirty(name, getFieldValue(field ? field._f : get(fields, name)._f), false, false, true);
1887
1878
  }
1888
1879
  };
1889
1880
  const register = (name, options = {}) => {
@@ -1901,7 +1892,6 @@ function createFormControl(props = {}) {
1901
1892
  _names.mount.add(name);
1902
1893
  if (field) {
1903
1894
  _setDisabledField({
1904
- field,
1905
1895
  disabled: isBoolean(options.disabled)
1906
1896
  ? options.disabled
1907
1897
  : _options.disabled,
@@ -2627,7 +2617,7 @@ function useForm(props = {}) {
2627
2617
  });
2628
2618
  if (!_formControl.current) {
2629
2619
  _formControl.current = {
2630
- ...(props.control ? props.control : createFormControl(props)),
2620
+ ...(props.formControl ? props.formControl : createFormControl(props)),
2631
2621
  formState,
2632
2622
  };
2633
2623
  }