my (unstyled) Drum Machine is here : https://codepen.io/tolkadot/pen/VEYGEO
I would really appreciate some constructive criticism
If you have any advice/suggestions on how to improve my code I’d love to hear it.
Avoid using document.getElementById(keyPressed).play();, use refs instead. That’s advice i got. How to set up refs:
Put in audio tag ref={this.Q}, then in constructor this.Q = React.createRef();, then in componentDidMount() put this.somevar = ReactDOM.findDOMNode(this.Q.current) then in componentWillUnmount() put this.somevar = ReactDOM.findDOMNode(this.Q.current). So when you call function watchKeyboard and compare if e.key===this.somevar.current.id and if it is, then executethis.somevar.play();. Of course since there a many sounds, you better put it inside a object or an array and use switch/case instead of bunch of if’s …