I have nearly finished the drum machine but there is something that I can’t get my head round and that is the key press. I thought I had it working but now the sound is going funny. Also eventually it ends up breaking if you press enough keys. I would not recommend listening with the sound on.
The project can be found here: React App
The code base is here: GitHub - Joseph-Worthington/drum-machine: This is a drum machine, part of the Freecodecamp curriculum for front end libraries. The app allows the user to create a drum beat using certain keys and their mouse.
Any help or advice would be greatly appreciated thank you.
Hey, I dont have the answer, but upon watching the logs in the inspector its recording 32 instances, 64, 96, and 128 at a time, while the click is normal 1,2,3,4. Maybe you can use that feedback to find a solution. Good luck
1 Like
In the useEffect
you are using to add the "keydown"
event listener you have to add a return that removes the listener as well. Also, it should have an empty dependencies array.
Look at the “Listening to a global browser event” example in the React docs.
1 Like
Thank you for pointing me in the right direction, I read through the documentation I think I understand it a bit better now.