Coding⏱️ 2 min read📅 2026-05-30

How to Fix: A component is changing an uncontrolled input of type text to be controlled error in ReactJS

Switch from uncontrolled to controlled input element in ReactJS

Quick Answer: Use the `value` attribute and update state with `onChange` event, or use a controlled component library like Material-UI or React Hook Form

In your code, you are updating the state of `fields` directly without using the `setState` method. This is causing the input element to lose its original uncontrolled behavior and become controlled unexpectedly.

⚠️ Fix: Use the `setState` Method

  • Update the state of `fields` using the `setState` method, like so:

Example:

  1. onChange(field, e) { this.setState({fields: {[field]: e.target.value}}});}

🔧 Why?

By using the `setState` method, you ensure that any changes to the state are handled by React and do not cause unexpected behavior.

✨ Wrapping Up

Make sure to update your code accordingly, and you should no longer receive the warning message about changing an uncontrolled input to a controlled one.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions