What are controlled components?

What are some examples?

4 Likes

Hello @codingperson51867872 !

In HTML, form elements such as <input> , <textarea> , and <select> typically maintain their own state and update it based on user input. When a user submits a form the values from the aforementioned elements are sent with the form. With React it works differently. The component containing the form will keep track of the value of the input in it’s state and will re-render the component each time the callback function e.g. onChange is fired as the state will be updated. A form element whose value is controlled by React in this way is called a “controlled component”.

With a controlled component, every state mutation will have an associated handler function. This makes it straightforward to modify or validate user input.

I hope this helps =)

Source: https://medium.com/@vigowebs/frequently-asked-react-js-interview-questions-and-answers-36f3dd99f486

5 Likes

Also see here for some examples also:

4 Likes