var TIMER_COMPONENT = ` class Timer extends React.Component { constructor(props) { super(props); this.state = {secondsElapsed: 0}; } tick() { this.setState((prevState) => ({ secondsElapsed: prevState.secondsElapsed + 1 })); } componentDidMount() { this.interval = setInterval(() => this.tick(), 1000); } componentWillUnmount() { clearInterval(this.interval); } render() { return (
Seconds Elapsed: {this.state.secondsElapsed}
); } } ReactDOM.render(, mountNode); `.trim(); ReactDOM.render( , document.getElementById('timerExample') );