Build the classic Minesweeper on a 9x9 board with 10 hidden mines. It's a small game with one genuinely interesting algorithm at its heart: clicking an empty square doesn't reveal just that square, it opens up the whole connected region of blanks — a flood fill. This React version holds the board in useState and derives every cell's look from it.
The starter App.tsx renders the board in its resting state — all 81 cells hidden, 🚩 10 remaining, a 🙂 reset button, and a "Click a cell" status. The mine positions are fixed (MINES) and each cell already knows its adjacent-mine count via buildBoard(). Make it playable:
useState(buildBoard) plus a status of playing, won, or lost.lost). A numbered cell just shows its count. An empty (0-adjacent) cell flood-fills: reveal it and every connected 0-cell, plus the numbered border around them.onContextMenu with e.preventDefault() toggles a 🚩 on a hidden cell.won.🙂 / 😵 / 😎) rebuilds the board.🚩 N counter drops by one. Right-click again to remove it.😵, and the status reads Lost.MINES is a hardcoded set of 10 indices so the board is deterministic — no Math.random.styles.css; focus on the state and the reveal logic.Unlock the solution & editor
Runnable editor + tests
Solve in the browser with instant Jest feedback.
Detailed solutions
Walkthroughs, edge cases, and complexity notes.
Multi-framework variants
React, Vue, Vanilla, Angular — same question, different stacks.