const React = global.React;
const ReactDOM = global.ReactDOM;
class Counter extends React.unstable_AsyncComponent {
state = {counter: 0};
onCommit() {
setImmediate(() => {
this.setState(state => ({
counter: state.counter + 1,
}));
});
}
componentDidMount() {
this.onCommit();
}
componentDidUpdate() {
this.onCommit();
}
render() {
return <h1>{this.state.counter}</h1>;
}
}
const interval = 200;
function block() {
const endTime = performance.now() + interval;
while (performance.now() < endTime) {}
}
setInterval(block, interval);
ReactDOM.render(<Counter />, document.getElementById('root'));
block();