import React, {Component} from 'react';
class Clock extends Component {
constructor(props) {
super(props);
this.state = {
vall: 0};
}
componentDidMount() {
this.setState({val: 5})
}
render() {
return (
<div>
<h1>Привет, мир!</h1>
</div>
);
}
}
export default Clock;
You may call setState() immediately in componentDidMount(). It will trigger an extra rendering, but it will happen before the browser updates the screen. This guarantees that even though the render() will be called twice in this case, the user won’t see the intermediate state.