Premium
React Dynamic Table (Rows × Columns)
Generate a dynamic table in React from row/column inputs. Normalize values, rebuild the grid on action, and render consistent labels so users can verify correct dimensions. Concepts: react, state, event-handlers. React focus: generate rows/cols with map and keep inputs controlled. Framework focus: React hooks (useState/useEffect),…
- Render a main UI that contains the dynamic table controls.
- Provide two numeric inputs: one for the number of rows and one…
What you’ll build / What this tests
This premium react coding focuses on React Dynamic Table (Rows × Columns). You’ll apply react and state thinking with easy level constraints. The prompt emphasizes Generate a dynamic table in React from row/column inputs. Normalize values, rebuild the grid on action,….
Learning goals
- Translate the prompt into a clear react API signature and return shape.
- Apply react, state, event-handlers techniques to implement react dynamic table (rows × columns).
- Handle easy edge cases without sacrificing readability.
- Reason about time/space complexity and trade-offs in react.
Key decisions to discuss
- Define the exact input/output contract before coding.
- Choose iteration vs higher-order methods for readability.
- Prioritize predictable edge-case handling over micro-optimizations.
Evaluation rubric
- Correctness: covers required behaviors and edge cases.
- Clarity: readable structure and predictable control flow.
- Complexity: avoids unnecessary work for large inputs.
- API discipline: no mutation of inputs; returns expected shape.
- Testability: solution is easy to unit test.
Constraints / Requirements
- Render a main UI that contains the dynamic table controls.
- Provide two numeric inputs: one for the number of rows and one for the number of columns.
- Provide a button (e.g. "Generate table") that rebuilds the table when clicked.
- Render an HTML table whose number of rows and columns matches the current inputs.
- Each cell should show something simple and visible, e.g. its row/column indices like R1C1.
- Initially, showing an empty state or no table is fine. After the first generate action, a table appears.
- Changing the row or column input and clicking the button updates the table dimensions.
- If the user enters non-positive values (0 or negative), the implementation may either render no rows/columns or clamp…
- Use React state (useState) to store the current numeric inputs (rows, columns) and the arrays driving the table.
- Keep separate state for the raw inputs and the derived arrays you map over (e.g. rows and cols).
Mini snippet (usage only)
// Example usage
const input = /* react dynamic table (rows × columns) input */;
const result = solve(input);
console.log(result);
// Edge case check
const empty = input ?? null;
const fallback = solve(input);
console.log(fallback);
// Expected: describe output shape, not the implementation
// (no solution code in preview)Common pitfalls
- Mutating inputs instead of returning a new value.
- Skipping edge cases like empty input, duplicates, or nulls.
- Overlooking time complexity for large inputs.
Related questions
Upgrade to FrontendAtlas Premium to unlock this challenge. Already upgraded? Sign in to continue.