InterviewSolution
| 1. |
What is a controlled and uncontrolled component? |
|
Answer» We can divide all React Native components into two categories based on the internal state of the component. There are controls LIKE textInput which have a value attribute. It is used to DISPLAY user input value on UI. If the value displayed is controlled by the form control then it is known as an uncontrolled component because React is not setting or changing the value of these components. But if the state of the component is maintained by the state of the component then these components are called a controlled component. To make a component controlled, we ASSIGN the state of the component as the value of control elements and add a CALLBACK METHOD which will update the state on each value change event. In React Native, it is preferred to have controlled component so that all the values and behaviour will get managed by React and developer will have full control over the state of components. |
|