Build a tiny spreadsheet: a grid of cells (columns A–D × rows 1–6) where a cell can hold a number, some text, or a formula like =A1+A2. A formula's value is computed from other cells, and editing a cell must recompute everything that depends on it. This is the core of any spreadsheet — a formula evaluator with dependency tracking — done as a single React component.
The starter App.tsx renders each cell's raw string (so A3 literally shows =A1+A2). Make it a working sheet:
evaluate(id, raw, seen): a non-formula cell returns its number (or text); a formula parses the expression after =, resolves each cell reference by recursively evaluating that cell, and computes + - * / and parentheses — without eval().evaluate(id, ...) in each cell instead of the raw string. A parse/reference error shows #ERR.#CYCLE instead of looping forever.A1 = 10, A2 = 20, cell A3 = =A1+A2 displays 30. Editing A1 to 12 makes A3 show 32 and every dependent cell update.Total shows Total; an empty cell shows nothing.A1 = =B1 and B1 = =A1, both cells show #CYCLE. A formula like =A1+ shows #ERR.useState; derive the displayed values with useMemo so an edit to raw recomputes the grid.eval(). Parse the arithmetic yourself (a small recursive-descent parser). eval() runs arbitrary code and can't see cross-cell references or cycles.A–D × 1–6. You don't need ranges (A1:A6) or functions like SUM — just refs and + - * / with parentheses.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.