Skip to content

Commit

Permalink
close #10096 react strict mode with mounted field value
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Mar 14, 2023
1 parent a68f683 commit ff224d5
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 @@ -19,6 +19,7 @@ import { useFormContext } from './useFormContext';
import { useFormState } from './useFormState';
import { useWatch } from './useWatch';
import { set } from './utils';
import isUndefined from './utils/isUndefined';

/**
* Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
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 ff224d5

Please sign in to comment.