Hook value updates to its initial value when using keydown event

Hi, everybody!

I’m developing calculator in React, and I can’t understand why when I click the number button several times, I can update hook to several numbers to display , but when I type the number with keyboard - the hook update to single value.

Here’s my Codepen:
https://codepen.io/Dimitrii1/pen/BaLQOym?editors=1010

Thanks a lot! :wink:

Your Keyboard component has no way of communicating state to it’s parent component Calculator (where the state is stored). You are passing it the clickedButton function via the pressButton prop and that’s it.

It looks like since useEffect runs once with every render there is no state to store additional changes.