Skip to content
tezvyn:
Menu

Architecting a composable DataTable API

Source: interviewHardHow cards are made

Summary

avoiding prop-bloat in a complex component.

Key points

separate a headless data/state core from rendering, use a column-definition config with custom cell renderers, expose composition over dozens of flags.

What's really being asked

The interviewer wants senior-level API design judgment: how to keep a complex, extensible component maintainable instead of accreting a prop for every feature.

The full answer

Separate concerns into a headless logic core and a presentation layer. The headless core, often a hook, owns data state: sort state and comparators, selected rows, and derived ordering, exposing state and handlers without rendering markup. Drive the table shape with a column-definition array rather than per-feature props: each column declares an id, a header, an accessor for its value, an optional comparator for sorting, and crucially an optional cell render function so consumers fully customize how any cell renders. Row selection becomes a feature on the core (selection state plus a getSelectionProps helper) instead of scattered props. For surrounding pieces like toolbars, empty states, or expandable rows, prefer composition and render props so consumers plug in custom UI. This is the model behind libraries like TanStack Table: a small, powerful core plus column configs and render functions, which scales to new features by adding a config field or composing a piece, not by adding another boolean to a giant component.

The mistakes people make

A monolithic DataTable with dozens of boolean and callback props that grows unboundedly. Hardcoding cell rendering so custom content is impossible. Coupling sorting and selection logic directly into rendering so neither can be reused or tested in isolation.

What usually comes next

How do you handle virtualization for large datasets? How does server-side sorting and pagination fit this API? How do you type column definitions for safety?

A concrete example

A useTable hook takes data and a columns array and returns sorted rows, sort handlers, and selection state. One column defines a custom cell renderer showing a status badge, another supplies a numeric comparator for sorting, and a checkbox column uses the selection helpers. Adding a new feature like column resizing extends the core and column config rather than adding props to a monolith.

Interview question

What architectural choice best prevents a feature-rich DataTable from becoming a monolith with dozens of props?

  • a.Hardcoding cell rendering and exposing only a data prop
  • b.A headless logic core plus a column-definition config with per-column render functionsCorrect
  • c.Putting all sorting and selection logic directly inside the render method
  • d.Adding a boolean prop for every feature like sortable, selectable, and renderable
Why?

Separating headless state from rendering and driving structure with column configs and render functions lets features scale via config rather than prop accretion. Per-feature booleans and hardcoded rendering are exactly what causes the monolith.

Just read this? Test yourself on what you have been reading.

Read the original → mui.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles