-
Notifications
You must be signed in to change notification settings - Fork 49.6k
Open
Labels
Description
Summary
After a form is submitted with an action
, if one of the form's fields is a checkbox or radio input controlled by its checked
prop, that element is reset as if it were uncontrolled. The same happens when the reset()
method is called on the form. (Expected behavior: those fields are not reset.)
import { useState } from "react"
export default function Page() {
const [isChecked, setIsChecked] = useState(false);
return (
<form action={() => {
console.log("hello world!");
}}>
<label>
Some checkbox
<input type="checkbox"
checked={isChecked}
onChange={(e) => {
setIsChecked(e.target.checked);
}}
/>
</label>
<button>Submit form</button>
</form>
);
}
Repro: https://codesandbox.io/p/sandbox/checkbox-reset-repro-sff3sr
Related: #30580, reactjs/react.dev#7340
ray-marr-ho, tomashauser, mfilipiec, joshuajaco, billyjanitsch and 4 moreMiroslavPetrik, jakewtaylor, billyjanitsch and johnloven