Skip to content

Commit

Permalink
✍️ close #10096 react strict mode with mounted field value (#10102)
Browse files Browse the repository at this point in the history
* close #10096 react strict mode with mounted field value

* fix lint error
  • Loading branch information
bluebill1049 authored Mar 14, 2023
1 parent a68f683 commit 5599c23
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/useController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import getEventValue from './logic/getEventValue';
import isNameInFieldArray from './logic/isNameInFieldArray';
import cloneObject from './utils/cloneObject';
import get from './utils/get';
import isUndefined from './utils/isUndefined';
import { EVENTS } from './constants';
import {
ControllerFieldState,
Expand Down Expand Up @@ -90,11 +91,11 @@ export function useController<
updateMounted(name, true);

if (_shouldUnregisterField) {
set(
control._defaultValues,
name,
cloneObject(get(control._options.defaultValues, name)),
);
const value = cloneObject(get(control._options.defaultValues, name));
set(control._defaultValues, name, value);
if (isUndefined(get(control._formValues, name))) {
set(control._formValues, name, value);
}
}

return () => {
Expand Down

0 comments on commit 5599c23

Please sign in to comment.