diff --git a/src/Metronome.js b/src/Metronome.js index 85f0c80..44ea061 100644 --- a/src/Metronome.js +++ b/src/Metronome.js @@ -24,7 +24,21 @@ class Metronome extends Component { handleBpmChange = event => { const bpm = event.target.value; - this.setState({bpm}); + + if (this.state.playing) { + // Stop the old timer and start a new one + clearInterval(this.timer); + this.timer = setInterval(this.playClick, (60 / bpm) * 1000); + + // Set the new BPM, and reset the beat counter + this.setState({ + count: 0, + bpm + }); + } else { + // Otherwise just update the BPM + this.setState({bpm}); + } }; playClick = () => {