Fixing the React warning “changing an uncontrolled input to be controlled”
React shows the warning A component is changing an uncontrolled input to be controlled. when an input's value is undefined at first and later becomes a string. To fix it, set the state's initial value to an empty string (''), or replace the value with an empty string before passing it, as in value={user?.name ?? ''}. The warning appears when a profile edit screen shows a name loaded from an API in an input, or when useState() is called with no argument.
In a test environment, I created inputs whose value starts as undefined in four different ways, confirmed that they produce this warning, and confirmed that the warning disappears after I fixed them.
The test environment was Ubuntu 24.04 with Node.js 22.23.5. I used a project created from the react-ts template of npm create vite@latest (react and react-dom 19.3.1, @types/react 19.3.0, Vite 8.3.8, TypeScript 7.0.2, oxlint 1.94.0), and wrapped the components in StrictMode. I opened the pages and operated them with Chromium 157 through Playwright 1.63.0. The DevTools screenshots were taken from a headed Chromium running on a virtual display (Xvfb). I did not test Next.js or other frameworks, form libraries such as React Hook Form, or browsers other than Chromium.
The message from a useState with no initial value
I created an input for a name and made the state with useState<string>(), without passing an initial value. Calling useState with no argument makes the first value undefined.
// Wrong: no initial value passed to useState (name is undefined at first)
import { useState } from 'react';
export default function NoInitial() {
const [name, setName] = useState<string>();
return (
<label>
名前:
<input value={name} onChange={(e) => setName(e.target.value)} />
</label>
);
}
When I opened the page with the development server (the same vite that npm run dev runs), no warning appeared. When I typed "tama" into the input, the input displayed "tama", and the following message appeared in the DevTools console.
A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://react.dev/link/controlled-components
The first sentence means that a component is changing an uncontrolled input into a controlled input. The second sentence says the likely cause is that value changed from undefined to a defined value. The third sentence asks you to decide, for as long as the input is displayed, whether it is controlled or uncontrolled.

React treats an input whose value is undefined as an input whose value React does not manage (an uncontrolled input). When you type and the state becomes a string, React sees a string passed to value and concludes that the input is now one whose value React manages (a controlled input). That is when it shows this warning. The console shows it as a red error line, but in the development build of react-dom 19.3.1, the code only calls console.error and does not throw. Rendering continues, and the input accepts text normally.
The official reference's troubleshooting section for this warning also says that you cannot pass value={undefined} first and a string later. React cannot tell whether you want the input to be controlled or uncontrolled. The same reference advises against passing null to a controlled input. The development build of react-dom also treated null and undefined the same way, as an uncontrolled input.
Three other patterns that end up with undefined
I tested three more patterns that produce the same warning. In each, the first value (or checked for checkboxes) is undefined.
The first pattern keeps the form values in an object state and passes a key that does not exist yet to value. If you start with useState<Form>({}), form.email is undefined at first.
// Wrong: the object state has no email key yet (form.email is undefined at first)
import { useState } from 'react';
type Form = { name?: string; email?: string };
export default function ObjectField() {
const [form, setForm] = useState<Form>({});
return (
<label>
メール:
<input
value={form.email}
onChange={(e) => setForm({ ...form, email: e.target.value })}
/>
</label>
);
}
The second pattern passes user?.name for data that has not loaded from the API yet. Before loading, user is undefined, so user?.name is also undefined. I used { "name": "たま", "email": "tama@example.com" } as the contents of /user.json.
// Wrong: user is undefined until the API data loads, so user?.name is also undefined
import { useEffect, useState } from 'react';
type User = { name: string; email: string };
export default function Fetched() {
const [user, setUser] = useState<User>();
useEffect(() => {
fetch('/user.json')
.then((res) => res.json())
.then((data: User) => setUser(data));
}, []);
return (
<label>
名前:
<input
value={user?.name}
onChange={(e) => user && setUser({ ...user, name: e.target.value })}
/>
</label>
);
}
The third pattern passes a useState<boolean>() with no initial value to a checkbox's checked.
// Wrong: no initial value passed to the checkbox state (agreed is undefined at first)
import { useState } from 'react';
export default function Checkbox() {
const [agreed, setAgreed] = useState<boolean>();
return (
<label>
<input type="checkbox" checked={agreed} onChange={(e) => setAgreed(e.target.checked)} />
利用規約に同意する
</label>
);
}
For the object-state input, the warning appeared when I typed "tama". For the checkbox, it appeared when I clicked it. The message was identical to the first one I saw, and it still says value even for the checkbox. In the development build of react-dom, the checkbox and radio cases check checked instead of value, but they emit the same message.
The version that loads from the API showed the warning without any input. When I opened the page, the input got "tama" after loading, and the same message appeared in the console. Because it appears regardless of user input, if a red line shows up as soon as the page opens, check the input that receives the loaded data.

TypeScript type checking does not catch it
All four components above passed the type check with npx tsc -p tsconfig.app.json --noEmit. The oxlint linter included in the template also reported nothing when I ran npx oxlint src with the default settings.
In the @types/react 19.3.0 type definitions, the value of input is string | readonly string[] | number | undefined, and checked is boolean | undefined. Both accept undefined. The state returned by useState<string>() has the type string | undefined, so it can be passed to value as is. Neither type checking nor linting catches this. I found it only when I ran the page and looked at the console.
Avoid starting with undefined: use an initial value or ?? '' to pass a string
The official troubleshooting section says that when a value comes from an API or state and may start as null or undefined, you should either start with an empty string or convert it to a string with value={someValue ?? ''}. It also says that a checkbox's checked should always be a boolean.
For useState with no initial value, passing an empty string as the initial value fixes it.
// Fixed: set the initial value of useState to an empty string
import { useState } from 'react';
export default function FixNoInitial() {
const [name, setName] = useState('');
return (
<label>
名前:
<input value={name} onChange={(e) => setName(e.target.value)} />
</label>
);
}
For an object state, put an empty string in every key of the initial value. I also removed the ? from the type.
// Fixed: the initial value of the object state has every key set to an empty string
import { useState } from 'react';
type Form = { name: string; email: string };
export default function FixObjectField() {
const [form, setForm] = useState<Form>({ name: '', email: '' });
return (
<label>
メール:
<input
value={form.email}
onChange={(e) => setForm({ ...form, email: e.target.value })}
/>
</label>
);
}
For the checkbox, I passed false as the initial value, as in useState(false).
For an input that is filled from the API, add ?? '' where the value is passed. Before loading, an empty string is passed, so the input is controlled from the start. I also added disabled so the user cannot type until the data has loaded.
// Fixed: before loading, pass an empty string with ??
import { useEffect, useState } from 'react';
type User = { name: string; email: string };
export default function FixFetched() {
const [user, setUser] = useState<User>();
useEffect(() => {
fetch('/user.json')
.then((res) => res.json())
.then((data: User) => setUser(data));
}, []);
return (
<label>
名前:
<input
value={user?.name ?? ''}
disabled={!user}
onChange={(e) => user && setUser({ ...user, name: e.target.value })}
/>
</label>
);
}
Another fix is to not render the input until loading finishes. While loading, show only a loading message (Loading…). After loading, render the input component with the loaded name as its initial value. Inside the input component, the state is a string from the start, so undefined never reaches value.
// Fixed: do not render the input until loading finishes, then pass the initial value
import { useEffect, useState } from 'react';
type User = { name: string; email: string };
function NameForm({ initialName }: { initialName: string }) {
const [name, setName] = useState(initialName);
return (
<label>
名前:
<input value={name} onChange={(e) => setName(e.target.value)} />
</label>
);
}
export default function FixFetchedAfterLoad() {
const [user, setUser] = useState<User>();
useEffect(() => {
fetch('/user.json')
.then((res) => res.json())
.then((data: User) => setUser(data));
}, []);
if (!user) return <p>読み込み中…</p>;
return <NameForm initialName={user.name} />;
}
I opened and operated all five fixed components the same way, and none of them showed the warning in the console. The display was the same as before the fix. Typing "tama" in the empty input showed "tama". The input loaded from the API showed "tama" from the start, and typing another "tama" made it "tamatama". The checkbox was checked when I clicked it.

The one remaining line is the React DevTools notice. It also appeared on the page before the fix.
In the second input, no warning appeared when I typed
I also opened a page with two inputs, one for the name and one for the email, both made with useState<string>() and no initial value. When I typed "tama" in the name input, one warning appeared. When I then typed into the email input, no second warning appeared. In the development build of react-dom 19.3.1, once this warning has been shown, the code sets a variable named didWarnUncontrolledToControlled to true and stops showing it again. After fixing one input, reload the page and type into the remaining inputs as well.
The production build of react-dom does not contain the text of this warning. Use the development server and check the console while you fix the code.





