here is the code sample :
class App extends Component {
constructor() {
super();
this.state = {
currentColor: "red"
};
while(1){
await this.changeColor();
}
}
changeColor = async () => {
console.log("123")
setTimeout(() => {
this.setState({
currentColor: "yellow"
});
setTimeout(() => {
this.setState({
currentColor: "green"
});
setTimeout(() => {
this.setState({
currentColor: "red"
});
}, 100);
}, 200);
}, 300);
};
render() {
return (
<div>
<div
className={this.state.currentColor}
style={{ width: "100px", height: "100px" }}
/>
</div>
);
}
}
when I add await in front of changeColor() , I got an ''Unexpected strict mode reserved word' error. the online code:https://stackblitz.com/edit/react-cm4jdq. (I want to right an traffic lights demo)