[Input] Should determine if the component is controlled at the mount time
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
The controlled/uncontrolled behavior is determined at the mount time.
Current Behavior
The controlled/uncontrolled behavior is determined at each render.
Steps to Reproduce (for bugs)
Look at the source code.
Context
@kgregory Raised this issue in #9523. It’s important to notice that the Input
component is the only component behaving this way. It’s no the case for: input
, Checkbox
, Switch
, Radio
, ExpansionPanel
and Tooltip
.
Your Environment
Tech | Version |
---|---|
Material-UI | v1.0.0-beta.24 |
React | v16.2.0 |
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
[Input] Should determine if the component is controlled at the ...
The controlled/uncontrolled behavior is determined at the mount time. Current Behavior. The controlled/uncontrolled behavior is determined at ...
Read more >A component is changing an uncontrolled input to be ...
Hint: you need to choose between controlled and uncontrolled components, so using ref would be solution for it. or Changing value to ...
Read more >FAQs | React Hook Form - Simple React forms validation
Components mount to the page faster than controlled components because they have less overhead. As a reference, there is a quick comparison test...
Read more >Uncontrolled Components - React
In a controlled component, form data is handled by a React component. The alternative is uncontrolled components, where form data is handled by...
Read more >Controlled vs Uncontrolled Components in React - ITNEXT
The data flow is uni-directional from the component state to the input element. Working with controlled components can be a bit cumbersome ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@oliviertassinari Fair enough, it’s your call - I agree about not making it more complicated (it was more a thought experiment about explicit intention vs implicit behavior).
I dug around to try and understand why React have frowned upon controlled state switching. It appears to only relate to components wrapping the underlying DOM elements of
<input>
<textarea>
and<select>
, as they are either directly controlling these elements, or handing control over to the underlying engine. So I’m not convinced it’s a convention - more so a pragmatic wariness (possibly due to performance and/or potential stability issues?) for those specific elements.One thing to be aware of is that users are already get the warning from react, but it still seems to work (switch control). So I don’t think they’ll notice anything except their code suddenly not working. Perhaps a new warning in Input should be added? Might be nice to have similar warnings if you’re not allowing control switching in other components (or just a note in the docs relating to those specific components/props could be equally effective).
Actually, let’s use
!= null
to save some bytes. We have the tests to cover our back.