What is the difference between controlled and uncontrolled components

Intro Line -

Both controlled and uncontrolled components in React are used for creating forms and managing user input, but they handle form state differently.

3 Points Compared and Contrasted -

Form State Management:

Controlled Components: The form data is handled by the state within the component. Every state mutation has an associated handler function, making React the "source of truth."

Uncontrolled Components: The form data is handled by the DOM itself. They're more traditional HTML form inputs.

Data Retrieval:

Controlled Components: Value can be retrieved directly from the state of the component.

Uncontrolled Components: Value can be retrieved using refs to point directly to a DOM element.

Validation and Handling Updates:

Controlled Components: As the state is controlled within the component, it's easier to integrate form validation or display the entered values back to the user.

Uncontrolled Components: These components are generally used for infrequently changed data or where state management isn't beneficial.