I am performing a tasks that takes a few seconds to complete and am trying to show an animated progress indicator. When attempting to set the state to update the indicator, it only updates after the task has been completed.
I have tried using callbacks to accomplish this, but it doesn't seem to be working.
import React, { Component } from 'react'
import { Lion as Button } from 'react-button-loaders'
class xx extends Component {
constructor(props){
super(props)
this.state = {
buttonState: ''
}
this.handleClick = this.handleClick.bind(this)
}
Test(){
// Do task that takes some time
this.setState({buttonState: 'finished'} // End animation
}
handleClick() {
this.setState({buttonState: 'loading'},
() => {
this.Test()
})
}
render() {
return (
<div>
<Button onClick={this.handleClick} state={this.state.buttonState}>Test
</Button>
</div>
);
}
}
export default xx;
Without setting the state to finished, the activity indicator only appears after the entire task has already completed.