-
Notifications
You must be signed in to change notification settings - Fork 50.1k
Description
onChange is a nicer name for what onInput does and the fact that it has propagated up to other high-level components as the default name is much nicer than onInput as a high level event name.
Generally it has been helpful for the many new-comers to React that don't know the DOM well (which is a lot more than the inverse). However, that doesn't change the fact that it can be confusing for people that are familiar.
Unfortunately, changing it now would cause confusion for everyone that already knows React.
The reason I'd like to change it now is because I'd like to get away from polyfilling it for uncontrolled components. This use case is filled with all kinds of imperative code which leads to edge cases. E.g. reading/setting e.target.value or reading/setting ref.value.
When you use controlled components you shouldn't need to touch them imperatively and therefore won't hit the edge cases. Ideally we should get away from reading from e.target.value and instead just pass the value directly to the event handler.
Proposal:
Controlled Components
onInput: Polyfilled and works likeonChangedoes today. It is allowed to over-fire many events even if nothing changed. May have special Fiber rules regarding synchronous flushing. Optional: Passvalueas second arg.onChange: Works likeonInputfor one version but warns about being deprecated and suggests switching toonInput. In next version it works like the browser but still warns and tells you to useonInputforever.
Optional: Add a getter/setter on DOM .value in development mode and warn if this is used directly.
Uncontrolled Components
onInput: Not polyfilled. Works however the browser works. Warns about browser differences if you don't also specifyonClick,onKeyDownand/oronKeyUp. The warnings suggests implementing those listeners to cover more edge cases, or switch to a controlled component.onChange: Not polyfilled. Works however the browser works.