playSound = () => {
this.audio.current.play();
const parent = this.audio.current.parentNode;
parent.classList.add('active')
const id = this.audio.current.id;
// Find sound in the sounds array
const {id: name} = sounds.find(sound => sound.letter === id)
const display = parent.parentNode;
// Use found sound name
display.querySelector('h1').innerText = name;
}
But the way you’ve written your code is not the way you should write React. You should leave DOM manipulation to React and don’t do document.get... everywhere.
In the code I posted you can check how volume slider is implemented. There are two places:
One is in the App where slider is a controlled component that changes volume state and passes it to the DrumPad where it is used. That is the React way.
Second one is in the keydown handler where the value is obtained using document.get.... This should be avoided in React code.
Your code, as it is written right now, has no benefit of using React. Actually it’s the other way around - it is made slower by unnecessary adding React and ReactDOM packages.