diff --git a/drum-machine/src/App.js b/drum-machine/src/App.js index 89c0081..22b7a52 100644 --- a/drum-machine/src/App.js +++ b/drum-machine/src/App.js @@ -210,28 +210,26 @@ class DrumPad extends React.Component { this.handleClick = this.handleClick.bind(this); } + componentDidMount() { + this.audio = document.getElementById(this.props.drumPadKey); + } + componentDidUpdate() { if (this.props.isKeyPressed) { this.handleClick(); } } - // TO-DO: refactor by handling props change here handleClick() { this.props.displayDrumPadPress(this.props.noteName); - this.audio = new Audio(this.props.audioSrc); - this.audio.currentTime = 0; - this.audio.volume = this.props.volume / 100; - if (this.props.power) { - this.audio.play(); - } + this.audio.play(); } render() { return (
);