You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
675 B
35 lines
675 B
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 (
|
|
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<Timer />, mountNode);
|
|
`.trim();
|
|
|
|
ReactDOM.render(
|
|
<ReactPlayground codeText={TIMER_COMPONENT} />,
|
|
document.getElementById('timerExample')
|
|
);
|
|
|