A React checkbox that ignores clicks or never changes state
You provided a `checked` prop to a form field without an `onChange` handler. This will render a read-only field.Short answer
A React checkbox that will not toggle is almost always controlled with nothing updating the value. Check the console for the checked-without-onChange warning, make sure checked is always a boolean and the handler reads e.target.checked, and if the state lives in Redux, make sure the reducer returns new objects.
Fix it fast
1Find out which cause you have
Open the browser console and click the checkbox once. A warning here names the cause; no warning points to the Redux and handler causes.
grep -rn 'type="checkbox"' src/2Match what you see, then jump to its fix
- 1
The console prints that a checked prop was provided without an onChange handler.checked is set but there is no onChangeFix - 2
The box flips back, or the state ends up as the string 'on' or the same value every time.The handler reads value instead of checkedFix - 3
A component is changing an uncontrolled input to be controlledchecked starts as undefined and later becomes a booleanFix - 4
The action shows in Redux DevTools but the checkbox does not re-render.A Redux reducer changes the old state objectFix
- 1
What does the error look like?
You provided a `checked` prop to a form field without an `onChange` handler. This will render a read-only field.A component is changing an uncontrolled input to be controlled
Cause 1 of 4
checked is set but there is no onChange
1Check
Look at the checkbox tag. With checked and no handler React renders a read-only field, so the click is ignored.
<input type="checkbox" checked={done} />2Fix
Add an onChange that updates the state. Use defaultChecked instead if you only need an initial value, or readOnly if the box is meant to be fixed.
<input
type="checkbox"
checked={done}
onChange={e => setDone(e.target.checked)}
/>3Verify
Click the box. It toggles and the warning is gone from the console.
npm run devConfirmed by react.dev
Cause 2 of 4
The handler reads value instead of checked
1Check
A checkbox reports its state in e.target.checked. Reading e.target.value does not say whether it is ticked.
grep -rn "target.value" src/ | grep -i check2Fix
Read e.target.checked in the handler and pass checked (not value) to the input.
const [on, setOn] = useState(false);
<input type="checkbox" checked={on} onChange={e => setOn(e.target.checked)} />3Verify
Log the state after each click. It alternates true and false.
console.log(on)Confirmed by react.dev
Cause 3 of 4
checked starts as undefined and later becomes a boolean
1Check
The value comes from data that has not loaded yet, such as data?.isChecked. React treats undefined as uncontrolled, then complains when it turns into true or false.
<input type="checkbox" checked={data?.isChecked} onChange={handle} />2Fix
Always pass a boolean.
<input type="checkbox" checked={data?.isChecked ?? false} onChange={handle} />3Verify
Reload the page. The warning no longer appears while data loads.
npm run devConfirmed by react.dev
Cause 4 of 4
A Redux reducer changes the old state object
1Check
useSelector compares the old and new values with ===. A hand-written reducer that mutates and returns the same object looks unchanged. In a Redux Toolkit store, a mutation error can also be thrown in development.
case 'todos/todoToggled':
state[0].completed = !state[0].completed
return state2Fix
Return new objects at each level you change, or write the reducer with createSlice, where the same code is safe.
case 'todos/todoToggled':
return state.map(t =>
t.id === action.payload ? { ...t, completed: !t.completed } : t
)3Verify
Click the checkbox. It updates, and the DevTools diff shows a changed value.
npm run devConfirmed by redux.js.org
How do I stop it coming back?
- Treat every checked or value prop as a pair with an onChange handler.
- Give state a real default (false, not undefined) before data loads.
- Use createSlice for reducers so accidental mutation cannot happen.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix