What are controlled components and uncontrolled components in ReactJS? How do they differ from each other?
Reactjs – What are React controlled components and uncontrolled components
react-componentreactjs
Related Topic
- Php – Setters/Getters, Visibility [ OOP ] in PHP
- Jquery – Problem Integrating jquery show-hide with Dynamic Drive Step Carousel Viewer v1.8
- R – Progress ABL: How to have windows open in same position on the screen as they opened last time
- Javascript – How to pass props to {this.props.children}
- Javascript – the difference between React Native and React
- C++ – How to prevent a globally overridden “new” operator from being linked in from external library
- C++ – Call pure virtual function from parent class
- Javascript – A component is changing an uncontrolled input of type text to be controlled error in ReactJS
Best Answer
This relates to stateful DOM components (form elements) and the React docs explain the difference:
props
and notifies changes through callbacks likeonChange
. A parent component "controls" it by handling the callback and managing its own state and passing the new values as props to the controlled component. You could also call this a "dumb component".ref
to find its current value when you need it. This is a bit more like traditional HTML.Most native React form components support both controlled and uncontrolled usage:
In most (or all) cases you should use controlled components.