What is difference between controlled and uncontrolled component in React-JS

Forums ReactWhat is difference between controlled and uncontrolled component in React-JS
Staff asked 3 years ago

Answers (2)

Add Answer
Krutvik Devmurari Marked As Accepted
Staff answered 3 years ago

Controlled component is component that get the changed value from the callback function and uncontrolled component is component that have the one from the DOM. For example, When input value is changed,we can use onChange function in Controlled Component and also we can get the value using DOM like ref.

Staff answered 3 years ago

Controlled component:
In a controlled component, the value of the input element is controlled by React. We store the state of the input element inside the code, and by using event-based callbacks, any changes made to the input element will be reflected in the code as well.
Uncontrolled component:
In an uncontrolled component, the value of the input element is handled by the DOM itself. Input elements inside uncontrolled components work just like normal HTML input form elements.

Subscribe

Select Categories