I would like to create a <textarea> that behaves like console.log.
class Console extends Component {
...
async componentDidMount() {
for (var i = 1; i < 10; i++) {
setTimeout(() => {this.setState({message: 'updateMessage' + millis()}, 1000);
}
}
render() {
return <textarea>{this.state.messsage}</textarea>
}
}
I expected this code to update the UI in realtime. The issue is that componentDidMount waits until all the setTimeout's functions are executed in the loop then renders everything all at once.
Is there something I am misunderstanding? Thanks