Check for Winning Conditions in React useReducer for Tic-Tac-Toe

InstructorKyle Shevlin

Share this video with your friends

Send Tweet

At this point, our game is fully usable. Users can add Xs and Os and can see for themselves who has won or not. However, this is a computer game now and it should be programmed to determine who the winner is algorithmically.

Breaking down the problem of tic-tac-toe, one will realize that there are only 8 winning conditions in the game. We can create a handful of functions that will checkForWin when a square is clicked. Once we have determined the winner, we can update the UI to announce that to the users.