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