react ライフサイクルメソッド

class App extends Component {
	constructor(props) {
		super(props);
		this.state = {
			current: new Date(),
		};
	}

	componentDidMount() {
		this.timer = setInterval(() => {
			this.setState({
				current: new Date(),
			});
		}, 1000);
	}

	componentWillUnmount() {
		clearInterval(this.timer);
	}

	render() {
		return (
			<div>
				<h1>{this.state.current.toLocaleString()}</h1>
			</div>
		);
	}
}