Skip to content

Commit

Permalink
[utils] Allow passing NaN as defaultValue to useControlled
Browse files Browse the repository at this point in the history
  • Loading branch information
iammminzzy committed Mar 20, 2024
1 parent 9585d28 commit a330197
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mui-utils/src/useControlled/useControlled.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function useControlled({ controlled, default: defaultProp, name,
const { current: defaultValue } = React.useRef(defaultProp);

React.useEffect(() => {
if (!isControlled && defaultValue !== defaultProp) {
if (!isControlled && !Object.is(defaultValue, defaultProp)) {
console.error(
[
`MUI: A component is changing the default ${state} state of an uncontrolled ${name} after being initialized. ` +
Expand Down
6 changes: 6 additions & 0 deletions packages/mui-utils/src/useControlled/useControlled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ describe('useControlled', () => {
setProps({ defaultValue: 1 });
}).not.toErrorDev();
});

it('should not raise a warning if setting NaN as the defaultValue when uncontrolled', () => {
expect(() => {
render(<TestComponent defaultValue={NaN}>{() => null}</TestComponent>);
}).not.toErrorDev();
});
});

0 comments on commit a330197

Please sign in to comment.