can someone tell me how to make this work in the loop fuction? how can I bind the loop function to constructor?
class Cookcoo extends React.Component{
constructor(props){
super(props);
this.state={
test:false
}
this.onPlay=this.onPlay.bind(this)
}
onPlay(){
(function loop() {
let randomTime = Math.round(Math.random() * 3000) + 500;
setTimeout(()=> {
this.setState({test:true});
setTimeout(()=>this.setState({test:false}),500)
loop();
}, randomTime);
}());
}
let that = this;and usethatinside loop function.