Knight Moves
Build a React component that displays a standard 8×8 chessboard. When the user hovers over a square, highlight all valid L-shaped knight moves from that square. When the mouse leaves the square, the highlights should disappear.
Requirements
-
Render a standard 8×8 chessboard (64 squares).
-
Each square should:
- Be styled as a black or white square based on position.
- Show a ♞ knight symbol on hover.
- Highlight all valid knight moves from that square.
-
Highlighting behavior:
- Use
.selected-squareclass for the hovered square. - Use
.knight-move-targetclass for valid knight move targets.
- Use
-
Interaction:
- Use
onMouseEnterto trigger highlighting. - Use
onMouseLeaveto reset highlights.
- Use
-
Each square should have a
data-testid="cell-{row}-{col}".
Edge Cases
- Corners like
(0,0)only show 2 moves. - Edges like
(0,3)or(7,4)show 4 moves. - Centers like
(3,3)show all 8 moves. - No square should be selected initially.
Reference UI

Companies:
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
