Inaccurate warning when value props is set without onChange.
See original GitHub issueWhen you create an input component and set its value
without providing an onChange
handler, React will log this to the console:
"You provided a
value
prop to a form field without anonChange
handler. This will render a read-only field. If the field should be mutable usedefaultValue
. Otherwise, set eitheronChange
orreadOnly
. "
This isn’t entirely accurate however. For example in my app I rely on event bubbling so that I can set a single onChange
on the form component, thereby saving my sanity preventing me from having to add an onChange
to every. single. field. (There are a lot in the app I’m working on)
Issue Analytics
- State:
- Created 10 years ago
- Reactions:78
- Comments:51 (12 by maintainers)
Top Results From Across the Web
You provided a `value` prop to a form field without an ...
Warning: Failed form propType: You provided a value prop to a form field without an onChange handler. This will render a read-only field....
Read more >Controller | React Hook Form - Simple React forms validation
This simplifies integrating with external controlled components with non-standard prop names. Provides onChange , onBlur , name , ref and value to the...
Read more >Deprecated prop for a React DOM element should not be used
React Warning: checkedLink prop on input is deprecated; set value and onChange instead. Was this documentation helpful? Analyze Your GitHub ...
Read more >API Reference - Formik
Returns true if values are not deeply equal from initial values, false otherwise. dirty is a readonly computed property and should not be...
Read more >API - React Select
Even when commonProps are not listed in the prop types below, a custom ... if the value entered in the field is invalid...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Evernight What do you mean, it ignores the mouse events? This is a strange case and you can write
onChange={function() {}}
to suppress the warning.What about adding:
onChange={()=>{}}
as an input attribute? It’s not perfect but it helps with the “warnings OCD” 😃