Skip to content

Commit

Permalink
fix #5492 with empty reset with useController setting unmount attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Jun 4, 2021
1 parent 8865bac commit 3ceccf7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/useController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ export function useController<
return () => {
controllerSubscription.unsubscribe();
const shouldUnmountField = shouldUnmount || shouldUnregister;
const field = get(fieldsRef.current, name);

if (
isFieldArray
? shouldUnmountField && !inFieldArrayActionRef.current
: shouldUnmountField
) {
unregister(name);
} else if (get(fieldsRef.current, name)) {
get(fieldsRef.current, name)._f.mount = false;
} else if (field && field._f) {
field._f.mount = false;
}
};
}, [name]);
Expand Down

0 comments on commit 3ceccf7

Please sign in to comment.