Drum Machine playing same sound for all buttons

Can anybody tell me where am I going wrong?

Drum machine is playing same sound for all buttons.


You create only one ref, then loop over the buttons and override that value each time. That’s why all buttons have the sound of the last button.
You can either create multiple refs or maybe use an array: createRef([])

Thank you. But I still couldn’t figure it out.

Your codepen doesn’t look like you’ve tried anything, what’s your updated code?

I tried creating array for ref but then everything stopped working. No buttons were responding, so I changed the code.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.