New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Unrelated state update in onKeyDown blocks onChange and breaks controlled component #19290
Comments
It looks like the state update in the This looks like a bug to me in the way these two events interplay. |
effect
on the onKeyDown
will cause input loss
Hi, I'm new here, trying to learn React architecture. @bvaughn Here is something that I found about the problem.
In this particular case, the problem is that within As an example of not using same queue (?), this particular example: useEffect(() => {
if (code === 'add') {
setCount(c => c + 1)
} else {
setCount(c => c - 1)
}
}, [code, setCount]) could be modified to: useEffect(() => {
if (code === 'add') {
setTimeout(() => setCount(c => c + 1), 0)
} else {
setTimeout(() => setCount(c => c - 1), 0)
}
}, [code, setCount]) and it will work. I hope it makes sense. |
Ran into this same issue, wrapping my setState call in a a setTimeout in the keydown handler fixed it. I'm curious to know if this is something that should work differently under the hood in React or if this error points to a bigger mistake or bad pattern on the developer side? |
This appears fixed in React 17. |
Hi, I use Input controlled mode and subscribe to
onKeyDown
andonChange
event. It will trigger an effect when user enter space. However, the space don't display on screen. Is this a bug on React or is there something wrong with the way I'm using it. But subscribe toonKeyUp
is normal. This is confused.React version: 16.13.1 and old
Steps To Reproduce
Link to code example:
The current behavior
input element can't receive the space
The expected behavior
input element can receive the space
The text was updated successfully, but these errors were encountered: