new in react here, don't know if it's right to do this on the setState callback like this?
setTimeout(()=> {
this.setState((state, props) => ({ activateLightColorForRed: true }), () => {
setTimeout(()=> {
this.setState(()=> ({ activateLightColorForRed: false }))
}, 500);
red.play();
})
}, toWait);
or maybe something like this?
this.setState((state, props) => {
this.setState((state, props) => {
activateLightColorForRed: true
});
setTimeout(() => { activateLightColorForRed: false },500)
})
are the state on the setState callback updated? something weird is happening in my components, it's rendering multiple times. I am not sure but I think it's because I'm doing the first sample?
setStateare asynchronous in nature and you could also use simplythis.setState({activateLightColorForRed:true})i.e. pass a object instead of passing in a function. Might help in readability. And yeah post the complete code for the component. It will help us. Thanks