import React, { Component } from 'react';
class Timer extends Component {
state = {
seconds: 0
};
componentDidMount() {
this.timer = setInterval(this.tick, 1000);
}
tick() {
this.setState({ seconds: this.state.seconds + 1 });
}
componentWillUnmount() {
clearInterval(this.timer);
}
render() {
return <h5>Прошло: {this.state.seconds}</h5>
}
}
export default Timer;