New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Autocomplete] An error occurs when changing multiple #21136
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
What can i do? |
@weizhi9958 You are right, the warning shouldn't be thrown in this context. Thanks for the report. What do you think of this patch? diff --git a/packages/material-ui/src/utils/useControlled.js b/packages/material-ui/src/utils/useControlled.js
index dab0f9039..730ccb30a 100644
--- a/packages/material-ui/src/utils/useControlled.js
+++ b/packages/material-ui/src/utils/useControlled.js
@@ -27,7 +27,7 @@ export default function useControlled({ controlled, default: defaultProp, name,
const { current: defaultValue } = React.useRef(defaultProp);
React.useEffect(() => {
- if (defaultValue !== defaultProp) {
+ if (!isControlled && defaultValue !== defaultProp) {
console.error(
[
`Material-UI: A component is changing the default ${state} state of an uncontrolled ${name} after being initialized. ` +
@@ -35,7 +35,7 @@ export default function useControlled({ controlled, default: defaultProp, name,
].join('\n'),
);
}
}, [JSON.stringify(defaultProp)]);
}
const setValueIfUncontrolled = React.useCallback((newValue) => { Do you want to submit a pull request? :) |
maybe could be better to check |
@marcosvega91 I don't know. I believe we use |
Thinking better you are right. Never mind 😃 |
Current Behavior
An error occurs when changing multiple
A component is changing the default value state of an uncontrolled Autocomplete after being initialized. To suppress this warning opt to use a controlled Autocomplete.
Expected Behavior
No error
Steps to Reproduce
https://codesandbox.io/s/solitary-http-e0zzh?file=/App.js
The text was updated successfully, but these errors were encountered: