Bug: input won't trigger onChange after a chain of setStates
See original GitHub issueReact-dom version: 16.9.0 to 16.12.0 (latest)
This bug was not present in 16.8.6
Steps To Reproduce
- Create a controlled input element
- Add an
onKeyDown
event handler that will change a state. - Add a
useEffect
hook that depends on the state from (2.), and changes another state - Try to type in something in the input
Link to code example: https://codesandbox.io/s/nostalgic-lake-zzynt
The current behavior
The input updates with the key the user has pressed
The expected behavior
The input doesn’t update. The handler for onKeyDown
was called, but the handler for onChange
wasn’t.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
React - setting input value with JavaScript does not trigger ' ...
Basically, the text input is a string (from an array) of user ID's - "2,46,3", etc. addMember is triggered when the app user...
Read more >react input onchange doesn't work
React app, after getting data from initial get request, onChange doesnt work. React JS : grandparent component's setState method doesn't update state of...
Read more >How to Use the setState Callback in React
To perform an action in a React component after calling setState, such as making an AJAX request or throwing an error, we use...
Read more >React setState does not immediately update the state
Reading state right after calling setState() a potential pitfall. useState React hook. Returns a stateful value, and a function to update it.
Read more >Simulate React On-Change On Controlled Components
For example, in many situations, we want to auto-update inputs. We do that either by using ... But triggering onChange without using setState...
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 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
This is fixed in 18 alpha. https://codesandbox.io/s/tender-glade-80ks5?file=/src/App.js
Unfortunately we won’t backport the fix to 17 because it was a complex refactor which relies on other things we’re putting in 18.
We haven’t touched that part but there are some post-17 changes planned that should simplify this. We’ll revisit at that point.