mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-25 23:05:23 +00:00
Now examples are trasnformed to GraphQL during build and assembled by the index template. This makes them easier to edit and tie in with their associated markdown description.
30 lines
507 B
JavaScript
30 lines
507 B
JavaScript
class Timer extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = { seconds: 0 };
|
|
}
|
|
|
|
tick() {
|
|
this.setState(prevState => ({
|
|
seconds: prevState.seconds + 1
|
|
}));
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.interval = setInterval(() => this.tick(), 1000);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
clearInterval(this.interval);
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div>
|
|
Seconds: {this.state.seconds}
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<Timer />, mountNode); |