Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

React warns that a form field has a value but no onChange handler

ErrorYou provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.

Short answer

React renders a field as read-only when you give it value (or checked) and no onChange. Pick the one that matches your intent: use defaultValue for an initial value only, add an onChange that updates state to control the field, or add readOnly if the value should never change. Checkboxes use checked, not value.

  • Applies to React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find the input named in the console stack trace and look at its props. Does it have value or checked without onChange? That single fact picks the fix.

    grep -rnE "value=\{|checked=\{" src/ | grep -v onChange
  2. 2Match what you see, then jump to its fix

    1. 1The text cannot be changed by typing, and the console shows the 'without an onChange handler' warningA controlled input with no handler to update the valueFix
    2. 2The value comes from props or an API and nothing in your code reads it back as the user editsYou only wanted an initial value, not a controlled fieldFix
    3. 3A value is shown on purpose, for example a generated code, and users should not edit itThe field is meant to be read-onlyFix
    4. 4The 'You provided a `checked` prop' warning, or a checkbox that never togglesA checkbox uses value instead of checked, or reads the wrong event fieldFix
    5. 5A component is changing an uncontrolled input to be controlledThe value starts as undefined or null and later becomes a stringFix

What does the error look like?

  • You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.
  • You provided a `checked` prop to a form field without an `onChange` handler.
  • A component is changing an uncontrolled input to be controlled

Cause 1 of 5

A controlled input with no handler to update the value

1Check

A field with a value prop is controlled: React forces it to show that value. If the state is not updated in onChange, every keystroke is reverted.

// the shape that triggers the warning
<input value={name} />

2Fix

Add an onChange that writes the new text into the state the value comes from.

const [name, setName] = useState('');
<input value={name} onChange={e => setName(e.target.value)} />

3Verify

Type in the field. The text appears and the warning is gone from the console.

# reload the page with the browser console open and type in the field

Confirmed by react.dev

Did this fix it?

Cause 2 of 5

You only wanted an initial value, not a controlled field

1Check

If the code never needs the live text in state, a controlled input is more than you need. defaultValue sets the starting text and leaves the field editable.

grep -rn "value=" src/components/ProfileForm.jsx

2Fix

Replace value with defaultValue (and checked with defaultChecked on a checkbox).

<input defaultValue={user.name} />
<input type="checkbox" defaultChecked={user.subscribed} />

3Verify

The field shows the starting text and can be edited without a warning.

# reload the page and edit the field

Confirmed by react.dev

Did this fix it?

Cause 3 of 5

The field is meant to be read-only

1Check

The warning says the field will render read-only. If that is what you want, say so with a prop, so React does not warn.

grep -rn "<input" src/ | grep -v onChange

2Fix

Add readOnly to the input.

<input value={code} readOnly={true} />

3Verify

The field still shows the value, cannot be edited, and logs no warning.

# reload the page and check the console

Confirmed by react.dev

Did this fix it?

Cause 4 of 5

A checkbox uses value instead of checked, or reads the wrong event field

1Check

Checkboxes need checked or defaultChecked, and the handler must read e.target.checked, not e.target.value.

grep -rn 'type="checkbox"' src/

2Fix

Control the checkbox with checked and read the boolean from the event.

<input
  type="checkbox"
  checked={accepted}
  onChange={e => setAccepted(e.target.checked)}
/>

3Verify

Click the box. It toggles and the console stays quiet.

# reload the page and click the checkbox

Confirmed by react.dev

Did this fix it?

Cause 5 of 5

The value starts as undefined or null and later becomes a string

1Check

A value that comes from an API call is often undefined on the first render. React then treats the input as uncontrolled, and switches when the data arrives.

grep -rn "useState()" src/

2Fix

Keep the value a string for the whole life of the input.

<input value={user.name ?? ''} onChange={e => setUser({ ...user, name: e.target.value })} />

3Verify

Load the page with the network throttled. The warning no longer appears when the data arrives.

# reload the page with browser devtools network throttling on

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Decide per field up front: controlled (value + onChange) or uncontrolled (defaultValue).
  • Initialise form state with empty strings, not undefined.
  • Search new code for inputs with value or checked and no onChange before merging.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.