Skip to content

Commit

Permalink
[base] Avoid calling setstate during renders (mui#34916)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored and felipe.richter committed Dec 6, 2022
1 parent 3164105 commit 32a2992
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ const FormControlUnstyled = React.forwardRef(function FormControlUnstyled<

const filled = hasValue(value);

const [focused, setFocused] = React.useState(false);
if (disabled && focused) {
setFocused(false);
}
const [focusedState, setFocused] = React.useState(false);
const focused = focusedState && !disabled;

React.useEffect(() => setFocused((isFocused) => (disabled ? false : isFocused)), [disabled]);

const ownerState: FormControlUnstyledOwnerState = {
...props,
Expand Down

0 comments on commit 32a2992

Please sign in to comment.