Prevent Impossible States and Check for Draw Conditions with Guard Statements in React

Share this video with your friends

Send Tweet

We should add some final touches to our tic-tac-toe game. We want to make sure that after a user has won, that it's impossible for them to put the game into a broken state. We can do that by adding a guard to our reducer.

It would also be nice if the board automatically reset in the result of a draw. We can add a checkForDraw function that algorithmically determines if the game is drawn or not and automatically reset the grid data.