<main></main>
const WithTimer = {
getInitialState() {
return { ticks: 0 };
},
componentDidMount() {
this._withTimer__clock = setInterval(() => {
this.setState({ ticks: this.state.ticks + 1 });
}, 1000);
},
componentWillUnmount() {
clearInterval(this._withTimer__clock);
},
};
const App = React.createClass({
getInitialState() { return {} },
mixins: [WithTimer],
render() {
return (
<div>
<p>Hello World {this.state.ticks} </p>
</div>
);
}
});
ReactDOM.render(<App />, document.querySelector('main'));
View Compiled
This Pen doesn't use any external CSS resources.