How come stepNumber: history.length in setState

Let us consider the user clicked the first button which index is 0

export default class Game extends React.Component {

constructor(props) {

    super(props)
    this.state = {
        xIsNext : true,
        stepNumber : 0,
        history :[
            {squares : Array(9).fill(null)}
        ]
    }
}


handleClick = (i) =>{
   const history = this.state.history
   const current = history[history.length - 1]
   const squares = current.squares
    squares[i] = (this.state.xIsNext) ? 'X' : 'O'

    this.setState({
        
        history : history.contact({squares : squares}),
        xIsNext:!this.state.xIsNext,
        stepNumber :history.length
        
    })
  }

render(){
    const history = this.state.history 
    const current = history[this.state.stepNumber]
    
    return (
        <div className="game">
            <div className="game-info">
            <Board />        
            </div>
        </div>
    )
}

}

stepNumber tells the current step number, which is basically the count of number of steps performed till now. We are maintaining a history variable whose length gets increased by 1 every time the state is updated. So it is logical to think that the length of history serves as value for stepNumber.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.