input.onChange has a new reference each time value changes
See original GitHub issueAre you submitting a bug report or a feature request?
Bug report
What is the current behavior?
Every time a field value changes, onChange gets a new reference (and maybe other event handlers do as well).
What is the expected behavior?
When building a custom field and using useEffect
, it’s frequent to depend on onChange
to update a value. In my case for a large field, I use useMemo
to make sure I only rerender the parts that need it, but onChange
makes sure everything gets updated every time the value changes. Is there another way than useCallback(input.onChange, [])
?
Sandbox Link
https://codesandbox.io/s/react-final-form-third-party-components-example-lo4yo?file=/index.js
What’s your environment?
(Latest on every lib, as seen on the sandbox)
Other information
/
Thanks in advance!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (4 by maintainers)
Top Results From Across the Web
ReactJs: Input onChange requires to be updated each time to ...
And the problem I am facing is that I have to enter a value into input field by click or selecting the input...
Read more >HTMLElement: change event - Web APIs | MDN
The change event is fired for , , and elements when the user modifies the element's value. Unlike the input event, the change...
Read more >oninput Event - W3Schools
This event occurs when the value of an <input> or <textarea> element is changed. Tip: This event is similar to the onchange event....
Read more >Input.onchange - JavaScript: The Definitive Guide, Fourth ...
The onchange property of an Input object specifies an event handler function that is invoked when the user changes the value displayed by...
Read more >lightning-input - documentation - Salesforce Developers
You can define an action for input events like blur , focus , and change . For example, to handle a change event...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
Here’s a test I wrote when investigating this. Please include it in the PR.
That’s the winning argument, I think. Callbacks a library gives you should be instance-stable across renders.
This will be a breaking change. @kapral18, can you PR this change?