Skip to content
Myr

docs: fix missing code highlights in tic-tac-toe tutorial (#3527)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Copilot · committed by GitHub · parent 07cee61 · Browse files · 1 file+5 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Diff stats

1 file+5 added−5 removed

  • other:+5 added−5 removed

1 file+5 added−5 removed

modified:docs/learn/guides/tutorial-tic-tac-toe.md+5 added-5 removed
565 unmodified lines
566`'Winner: O'`. To do that you'll add a `status` section to the `Board` component. The status will567display the winner or draw if the game is over and if the game is ongoing you'll display which568player's turn is next:569570```jsx {6-7,9,21}570```jsx {6-7,9,20-21,40}571export default function Board() {572 const xIsNext = useGameStore((state) => state.xIsNext)573 const setXIsNext = useGameStore((state) => state.setXIsNext)574 const squares = useGameStore((state) => state.squares)
370 unmodified lines
945Let's make the `Board` component fully controlled by the props it receives. To do this, we'll modify946the `Board` component to accept three props: `xIsNext`, `squares`, and a new `onPlay` function that947the `Board` component can call with the updated squares array when a player makes a move.948949```jsx {1}949```jsx {1,11}950function Board({ xIsNext, squares, onPlay }) {951 const winner = calculateWinner(squares)952 const turns = calculateTurns(squares)953 const player = xIsNext ? 'X' : 'O'
217 unmodified lines
1171You'll use `map` to transform your `history` of moves into React elements representing buttons on the1172screen, and display a list of buttons to **jump** to past moves. Let's `map` over the `history` in1173the `Game` component:11741175```jsx {29-44}1175```jsx {13-15,29-44}1176export default function Game() {1177 const history = useGameStore((state) => state.history)1178 const setHistory = useGameStore((state) => state.setHistory)1179 const xIsNext = useGameStore((state) => state.xIsNext)
113 unmodified lines
12931294Finally, you will modify the `Game` component to render the currently selected move, instead of1295always rendering the final move:12961297```jsx {2-8}1297```jsx {4-5,8}1298export default function Game() {1299 const history = useGameStore((state) => state.history)1300 const setHistory = useGameStore((state) => state.setHistory)1301 const currentMove = useGameStore((state) => state.currentMove)
57 unmodified lines
1359There's no need to store `xIsNext` separately in the state. It’s better to avoid redundant state1360because it can reduce bugs and make your code easier to understand. Instead, you can calculate1361`xIsNext` based on `currentMove`:13621363```jsx {2-5,13,17}1363```jsx {6,13,17}1364export default function Game() {1365 const history = useGameStore((state) => state.history)1366 const setHistory = useGameStore((state) => state.setHistory)1367 const currentMove = useGameStore((state) => state.currentMove)
62 unmodified lines