Frontend School

Paginated User Data Table

Machine Coding
medium

Paginated User Data Table

Medium
React
TypeScript
Frontend
Pagination
UI

Overview

In many enterprise applications, displaying large datasets efficiently is crucial. Without proper handling, a long list of items can be overwhelming and impact performance. Pagination is a common and effective technique to break down large data into smaller, manageable chunks, improving both user experience and application responsiveness.

This problem asks you to build a reusable client-side paginated data table component. This is a fundamental skill for any frontend engineer, ensuring users can navigate through extensive information without performance bottlenecks or excessive scrolling.

What you need to do / Task

Your task is to implement a React component that displays a list of user profiles in a table, complete with client-side pagination controls. The component should be able to paginate through a given array of data, displaying a fixed number of items per page.

Specifically, you must:

  1. Render a Data Table: Display the provided mockUserData in an HTML table with appropriate headers (ID, Name, Email, Role).
  2. Implement Pagination Controls: Below the table, render a set of pagination controls including:
    • 'Previous' button.
    • Page number buttons (e.g., 1, 2, 3...). The current page should be visually distinct.
    • 'Next' button.
  3. Manage Page State: When a 'Previous', 'Next', or page number button is clicked, the table content should update to show the items corresponding to the selected page.
  4. Handle Boundary Conditions: The 'Previous' button should be disabled when on the first page, and the 'Next' button should be disabled when on the last page.
  5. Accessibility: Ensure the pagination controls are accessible (e.g., using semantic HTML, ARIA attributes for navigation).

UI/UX expectations

  • The data should be presented in a clear, readable table format.
  • Pagination controls should be placed prominently below the table.
  • The current page number should be clearly highlighted or styled differently from inactive page numbers.
  • Disabled 'Previous'/'Next' buttons should be visually distinct (e.g., greyed out, unclickable).
  • The entire component should be reasonably styled for clarity, but extensive visual design is not required.

Acceptance criteria

  • The table correctly displays the headers and data from mockUserData.
  • Only PAGINATION_PAGE_SIZE items are displayed on the table at any given time.
  • Clicking 'Next' advances to the subsequent page, displaying new data.
  • Clicking 'Previous' reverts to the prior page, displaying new data.
  • Clicking a specific page number button navigates directly to that page.
  • The 'Previous' button is disabled when the current page is 1.
  • The 'Next' button is disabled when the current page is the last available page.
  • The active page number is visually indicated.
  • The pagination controls are navigable and understandable for users with assistive technologies (e.g., keyboard navigation, screen reader compatibility).

Constraints

Constraints & assumptions

  • The data for the table (mockUserData) is provided as a static array within App.tsx.
  • All pagination logic must be implemented client-side; no API calls are required.
  • The number of items per page is fixed by the PAGINATION_PAGE_SIZE constant.
  • You should use React functional components and hooks (useState, useEffect).
  • Focus on core functionality and clean code rather than elaborate styling.

Out of scope

  • Server-side pagination implementation.
  • Dynamic page size selection.
  • Sorting, filtering, or searching capabilities for the data.
  • Complex error handling or loading states.
  • Integration with external UI component libraries (e.g., Material UI, Ant Design).

What interviewers evaluate

  • Correctness and robustness of the pagination logic and state management.
  • Cleanliness, readability, and maintainability of the React component code.
  • Effective use of React hooks and TypeScript for type safety.
  • Adherence to basic UI/UX principles and accessibility best practices for interactive components.

Loading editor...