Using React Hooks to Build a Tic-Tac-Toe Game with Kent C. Dodds

Joel Hooks
InstructorJoel Hooks

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 2 years ago

To help accelerate our understanding of React Hooks, Kent is going to live-code a tic-tac-toe app from the ground up taking a Hooks first approach!

Hooks allow you to better separate your app's visual components from its state and functionality. Kent takes an accessibility and readability first approach to React development, so using hooks to separate your concerns makes your app easier to debug as well as reducing the mental and visual overhead when you are making sense of the code, making your code all around more maintainable.


  • Data is static information, state changes over your component's lifetime

  • Reducers let you move logic from your component to your pure reducer function. Changes to state always go to the same function, it's great for debugging.

  • Reducer concepts are covered excellently in Dan Abramov's Getting Started with Redux course

Tony Catalfo
Tony Catalfo
~ 4 years ago

Sorry, that was a mess. const Board=()=>{ const [squares, setSquares]= useState(Array(9).fill(null)) const[xIsNext, setXisNext]=useState(true) const selectSquare=(square)=>{ const xOrO=(elm,i)=>{ if(i !==square || elm !==null)return elm return (xIsNext)? "X":"O" } let // console.log('squaresCopy ',squaresCopy[square]='x') setSquares(squaresCopy) console.log(squares,squaresCopy) let status; if (calculateWinner(squaresCopy)){ status = "Winner: " + ((xIsNext) ? "X" : "O") }else{ status = "Next Player: " + ((xIsNext) ? "X" : "O") } console.log(status) setXisNext(x=>!x)


return (

  <div className='status'>{status}</div>