A React application that displays a paginated, selectable list of contacts.
The app fetches contact data in batches and lets users browse, load more items, and select contacts. Selected contacts are visually highlighted and pinned to the top of the list. The implementation focuses on clear UX (loading and error states, retry on failure) and on list performance when selecting, deselecting, and scrolling.
- React with TypeScript
- Create React App
- Testing Library (React, user-event, jest-dom) for component tests
Dependencies are kept minimal; the code is written manually without extra libraries beyond what is needed.
The application implements the following behaviour (aligned with the original specification):
- Paginated data — Contacts are fetched using the
apiDatafunction, with 10 items per batch. - Load more — A “Load more” button at the bottom of the list fetches the next batch and appends it to the existing list.
- Loading state — A spinner/loader is shown while a batch is being fetched.
- Error state — When a fetch fails, an error state is shown with an option to refetch the failed batch (e.g. “Try again”).
- Selectable cards — Each contact card is clickable and can be selected.
- Selected styling — Selected contacts have a visible outline (or equivalent visual distinction).
- Deselection — Clicking a selected card again deselects it.
- Selected at top — Selected contacts are displayed at the top of the list.
- Performance — The list is optimized for smooth interaction when selecting, deselecting, and scrolling.
Design and layout follow the provided pattern, with UX in mind.
The project includes functional/unit tests in src/tests/ContactList.test.tsx. They cover:
- Pagination (10 items per batch)
- “Load more” button fetching and appending the next batch
- Loading state visibility
- Error state and “Try again” refetch
- Card selection and deselection
- Selected cards having the correct outline/class
- Selected contacts appearing at the top of the list
Run tests:
yarn test- Node.js
- Yarn (or npm)
yarn install
yarn startOpen http://localhost:3000 to view the app.
yarn buildThe built app is output to the build folder.
The UI is organized using an atomic-style structure:
- atoms — Button, Heading, PersonAvatar, Spinner, Text
- molecules — ContactItem, ErrorState, LoadingState
- organisms — ContactList (orchestrates data fetching, pagination, selection, and list order)
Data is fetched via src/api.ts; types are defined in src/types.ts.