Closed
Description
Hi there! 👋
The following code produces a warning from React (see below):
<input
type="checkbox"
checked={marketingConsent}
onClick={(event) => {
setMarketingConsent(event.currentTarget.checked);
}}
/>
This is the warning:
Warning: You provided a `checked` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultChecked`. Otherwise, set either `onChange` or `readOnly`.
Since React shows a warning for it, maybe there can be a lint rule for it too? To guide developers towards either:
- usage of
onChange
orreadOnly
props withchecked
prop on aninput
- usage of
defaultChecked
for uncontrolled components