In my (class) component I want to show Loading spinner for the duration of the _expensiveFunction. Value isLoading was changed in the state before the function was executed, but it will not be re-rendered (spinner does not spin) until _expensiveFunction is complete.
I tried it with componentDidUpdate and forceUpdate, but without success.
_makeCalculation() {
this.setState(
{ isLoading: true },
() => this._expensiveFunction(),
);
}
_expensiveFunction() {
console.log(this.state.isLoading); // => true
// ***
this.setState({ isLoading: false });
}