When to use React setState callback

Yes there is, since setState works in an asynchronous way. That means after calling setState the this.state variable is not immediately changed. so if you want to perform an action immediately after setting state on a state variable and then return a result, a callback will be useful Consider the example below …. changeTitle: function … Read more

React setState not updating state

setState() is usually asynchronous, which means that at the time you console.log the state, it’s not updated yet. Try putting the log in the callback of the setState() method. It is executed after the state change is complete: this.setState({ dealersOverallTotal: total }, () => { console.log(this.state.dealersOverallTotal, ‘dealersOverallTotal1’); });