I am learning React, and followed this tutorial to create a simple Tic-Tac-Toe game that you can view here in CodePen.
I am confused about how the arrow function works in the onClick
property of the Square component that is being returned inside of the renderSquare
function of the Board component: onClick={() => this.props.onClick(i)}
. And also again similarly the Game component where I have onClick={ (i) => this.handleClick(i)}
. I assumed I could write it without the arrow function (just like onClick={this.handleClick(i)}
) but this breaks the game.