-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
useEffect
doesn't work for keydown
event listener
#15815
Comments
If you remove this Here's a fiddle that works just fine: https://codepen.io/anon/pen/oRVOgK |
Also you can put
|
That makes sense, thanks. |
Worked for me, thanks |
I have a stateless component which needs to listen on keyboard event. It adds keydown listener when the component is mounted and remove it when the component is unmounted. There is a state test is boolean value. It is set to true when the component is mounted. But in the keydown event listener, its value always false. It looks like the listener doesn't take the state reference. What's wrong with my code?
A live example can be found at: https://codepen.io/zhaoyi0113/pen/mYozVp
The text was updated successfully, but these errors were encountered: