← Questions

Paginated, sortable React table

0
MetaCodingLast asked Aug 2025

A coding interview question asked in Meta's technical phone screen, last asked Aug 2025. It tests react, frontend and components.

Build a React table component that takes its rows and its column definitions as data, sorts by a column when the user clicks its header, and splits the rows into pages. Focus on a clean split into components and a clear design of the state.

Interface

Unless you agree on a different interface with the interviewer, assume:

type Column<T> = {
  key: string;
  header: string;
  accessor: (row: T) => string | number;
  sortable?: boolean;
  render?: (row: T) => React.ReactNode;
};

<DataTable<T> rows={rows} columns={columns} pageSize={10} />
  • Clicking a sortable header sorts ascending, a second click descending, a third click clears the sort.
  • Pagination shows the current page, the page count, and previous and next buttons. Changing the sort goes back to page 1.

Example

rows: 23 users;  columns: name, age, city;  pageSize 10

initial            ->  page 1 of 3, rows 1-10 in input order
click "age"        ->  sorted by age ascending, page 1
click "age" again  ->  sorted by age descending
next, next         ->  page 3 of 3, showing 3 rows

Constraints

  • No table library. Plain React with hooks. Any styling approach.
  • Columns can change at runtime (added, removed, reordered).

Clarifying questions

  • Is sorting and paging done in the browser, or on the server through an API?
  • How many rows can there be?
  • Should the sort and page live in the URL?
  • Is sorting stable, and how are nulls and mixed types ordered?

What a strong answer covers

  • A decomposition such as DataTable, TableHeader, TableBody, Pagination, with state kept in one place: sort: {key, direction} | null and page.
  • Derived data, not stored data: sorted rows and the current page computed with useMemo from props and state.
  • A stable sort with a comparator per column, and correct handling of numbers, strings and empty values.
  • Accessibility: buttons in headers, aria-sort, keyboard use.
  • Tests for sorting order, the page boundaries and the reset to page 1.

Follow-ups

  • Make it extensible: filtering, column resizing, row selection, custom cell renderers.
  • Server-side sorting and paging for a million rows, with loading and error states.
  • A responsive layout for phones: stacked cards, or hiding low-priority columns.
  • Virtualize rows instead of paging.

Where it's asked

  • Meta · Technical phone screen · Last asked Aug 202545 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted

What it tests

react · frontend · components

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding