# HG changeset patch # User Alexandre Segura # Date 1497283753 -7200 # Node ID abf9f3ff2635b6105d0c90eecef8ebc83cf5a883 # Parent 6161392ca92824ba4de0ae45bb0ce5736b7ead89 Clear interval when component unmounts. diff -r 6161392ca928 -r abf9f3ff2635 client/src/components/Clock.js --- a/client/src/components/Clock.js Mon Jun 12 11:39:47 2017 +0200 +++ b/client/src/components/Clock.js Mon Jun 12 18:09:13 2017 +0200 @@ -6,13 +6,20 @@ state = { time: moment().format('H:mm:ss'), + intervalID: null } componentDidMount() { - setInterval(() => { + const intervalID = setInterval(() => { const time = moment().format('H:mm:ss'); this.setState({ time }); }, 1000); + + this.setState({ intervalID }); + } + + componentWillUnmount() { + clearInterval(this.state.intervalID); } render() {