My experience with the uncontrolled to controlled input error

Guide to avoid the Changing from Uncontrolled input to Controlled warning in React: define value from the start, use defaultValue or String(), and best practices with register and Controller for robust forms.

domingo, 17 de agosto de 2025 • 2 min read • Q2BSTUDIO Team

Artificial-Intelligence-

My personal experience with the Changing from Uncontrolled input to Controlled error

When I started building forms in my current project, this message appeared in the console: A component is changing an uncontrolled input to be controlled. This showed up as a red flag every time I loaded the form and was the clue to find a small but important design flaw.

The root cause

An uncontrolled input becomes controlled if its value prop changes from undefined to a defined value after the first render.

Example of the problem: <input value={formData.name} onChange={handleChange} />

If formData.name is undefined at the beginning, React treats the input as uncontrolled. When the data loads and formData.name gets a value like User, React detects that the input has changed from uncontrolled to controlled and throws the warning.

How I solved it

I made sure the value was always defined even before the data finished loading. For example: <input value={formData.name ?? String()} onChange={handleChange} />

When I use React Hook Form, it is important to provide an explicit defaultValue to avoid this state change: <input {...register(fieldName)} defaultValue={String()} />

For controlled components wrapped with Controller, it is also advisable to initialize defaultValue: <Controller name={fieldName} control={control} defaultValue={String()} render={({ field }) => <InputText {...field} /> />

Lesson learned

Deciding from the start whether an input will be controlled or not is key. If you choose controlled, initialize value with an empty string or with a reasonable default value using expressions like String() in JSX to avoid undefined. If you choose uncontrolled, avoid binding value and use defaultValue or refs.

How this fits with our work at Q2BSTUDIO

At Q2BSTUDIO, a custom software and application development company, we apply these best practices in every project. We are specialists in artificial intelligence, cybersecurity, and aws and azure cloud services, and we develop custom software solutions that include robust forms and predictable state management. We also offer business intelligence services, power bi implementations, and AI agents to integrate artificial intelligence and AI for companies in production processes.

Avoiding errors like the change from uncontrolled to controlled input saves debugging time and improves product quality. At Q2BSTUDIO, we combine technical experience in custom application development with knowledge in security and cloud services to deliver scalable and secure solutions.

If you need support in custom software, artificial intelligence, cybersecurity, aws and azure cloud services, business intelligence services, or implementing AI agents and power bi for your company, at Q2BSTUDIO we can help you design forms and React components following best practices to avoid errors and optimize the user experience.

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.