You've built todo apps, counters, and forms. But can you handle a grid of 50 cells that reference each other through formulas? This challenge pushes your state management skills into real spreadsheet territory โ formula evaluation, two-way cell bindings, and an interface that juggles editing, selection, and keyboard shortcuts all at once.
๐งฉ Overview
Build a spreadsheet with real-time formula evaluation. You'll wire up a 10-row ร 5-column grid where cells support basic values and Excel-style formulas (like =A1+B2), column and row selection, and a formula bar that mirrors what you're typing.
โ Requirements
- Render a spreadsheet with column headers A through E and rows 1 through 10
- Each cell uses an
<output>element for the computed value and an<input>overlaid for editing - Click a cell to edit; press Enter or blur to commit the change
- Formulas starting with
=must be evaluated:- Arithmetic:
=1+1โ2 - Cell references: A1=
5and B1==A1+3โ8
- Arithmetic:
- Click a column header to select/deselect that column
- Click a row number to select/deselect that row
- Selecting a column deselects any row and vice-versa
- Backspace clears the selected column or row
- Click outside the table deselects everything
- A formula bar (
fx) mirrors the editing cell's value - Cells must start empty โ no default values
๐ก Notes
- Use
useStatefor cells, selected column, and selected row. No need for useReducer here. - Each cell uses two overlapping layers: a visible
<output>for the computed value and an invisible<input>for the raw formula. Toggle withopacity-0/opacity-100so the input stays mounted. - Evaluate formulas with
eval: generate JSconstdeclarations from all cell values, wrap them in an IIFE, and evaluate. Recompute every cell on any change โ cells can reference each other.
๐งช Tests
- renders the app title
- renders the spreadsheet with column headers A-E and rows 1-10
- renders cells with initial empty values
- allows editing a cell and displays the new computed value
- evaluates a simple formula
- evaluates a formula with cell references
- re-evaluates formulas when a referenced cell is cleared
- selects a column when clicking the column header
- deselects column when clicking the same header again
- selects a row when clicking the row number
- deselects row when clicking the same row number again
- deselects column when selecting a row and vice-versa
- clears the column when Backspace is pressed with a column selected
- clears the row when Backspace is pressed with a row selected
- deselects column when clicking outside the spreadsheet
This one will stretch your understanding of React state in ways a simple counter or todo list never could. Formula engines, overlay editing, and cascading recomputation โ all with just hooks and vanilla React.
Top comments (0)