Earlier quoted context omitted.
Even with state, his code is overly verbose and can be expressed in a much more idiomatic way. var weAreConnected = Math.floor(Math.random() * 10) > 5; if (weAreConnected === true) { this.setState({ isConnected: true }) } else { this.setState({ isConnected: false }) } } turns into var weAreConnected = Math.floor(Math.random() * 10) > 5; this.setState({ isConnected: weAreConnected }); It's almost like he wrote it in t…
It didn't need to happen in componentDidMount with multiple calls to setState. If it's not getting info that it would only know after mounting, it could have happened in the same line that isConnected is initially defined within the constructor!
constructor() {
super()
this.state = {
isConnected: Math.floor(Math.random() * 10) > 5
}
}