Building the Drum machine project! Have abstracted almost all of my data from the state of each individual drum pad React component to the Redux store. I try to trace the data flow with logs and I can see that, when clicking on any of them, the action creator is triggered, the reducer is triggered, and, when I subscribe a console.log statement to the store, that the state in the store is changing as well.
I’m returning a new state with the reducer so the issue is not state immutability. Also, I am using connect and mapStateToProps so theoretically the component is subscribed too.
Also I tried to use onKeyPress on each audio element and I’m getting no luck with that. Do I need to have the onKeyPress element on an or because if so, don’t know how this would work! Also, is it logical to have the key logic on each individual audio element versus something global to handle it? The only reason I avoided abstracting that to the store was because it seemed like I then would have to figure out some way to get every audio element reference to the store which seemed unnecessarily complicated.
for the first problem you have, getting it to play when you press a key, I would advise adding a keyCode prop to each Pad element and your handleKeyPress would look something like this:
Just to add onto kravmaguy’s suggestion, I prefer event.key since it’s more readable (i.e. if you console log while pressing the c key it will show “c” instead of a numeric code). Plus, MDN shows keyCode as being deprecated.