set the isync state so you don't see the value update when console.log appears. You must have a status value printed in the user interface so that you can see what is happening. To fix the console log, try this.
class QuestionList extends React.Component { constructor(props) { super(props); this.state = {value: 0}; } handleClick = (prevState) => { this.setState({value: prevState.value + 1}, () => { console.log(this.state.value) }); }
NOTE. When you define the built-in lambda (arrow function) for the this reacting class, it is bound correctly, so you do not need to bind it in the constructor.
you can also change the way the previous number is transmitted if its just incrementing a state like this
handleClick = () => { this.setState({value: this.state.value + 1}, () => { console.log(this.state.value) }); }
source share