re: How to pass state between components in reactjs VIEW POST

FULL DISCUSSION
 

salem
nice explanation but it's not recommended to use :
this.setState({status: !this.state.status}, this.updateLibraryCount);
|.|
|_|
V
this.setState({status: !this.state.status} you better use

this.setState((prevState) => {
return { status: !prevState.status }
})

 
 

setState happens asynchronously... Therefore you need to use previous state first to ensure you are using the latest if you are going to calculate the state based on previous state.

code of conduct - report abuse