Infinite-scroll news feed in TypeScript
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Perplexity's coding round, last asked Apr 2026. It tests frontend, typescript and pagination.
Build a page that shows a feed of article cards and loads more as the reader scrolls toward the bottom, using the mock data and fetch helper you are given. The interviewer looks at component structure, how pagination state is kept, loading and error handling, and a layout that works from phone to desktop.
Interface
Unless you agree on a different setup with the interviewer, assume (React and TypeScript):
type Article = { id: string; title: string; summary: string; imageUrl?: string; source: string; publishedAt: string };
// given: resolves after a random delay, sometimes rejects
function fetchArticles(params: { cursor: string | null; limit: number }):
Promise<{ items: Article[]; nextCursor: string | null }>;
-
<Feed />— the page. Loads the first page on mount, then the next page when the reader nears the end. -
<ArticleCard article={...} />— one card: image (if any), title, summary, source and relative time. - A custom hook such as
useInfiniteArticles(limit)returning{ items, status, error, hasMore, loadMore, retry }.
Example
mount -> skeleton cards, then 20 articles (cursor "c1")
scroll near end -> a spinner under the list, then 20 more (cursor "c2")
fetch fails -> "Couldn't load more. Retry" under the list; the 40 cards stay
retry -> the same cursor "c2" is requested again
nextCursor null -> "You're all caught up"; no more requests
Constraints
- Never request the same page twice at once, and never show the same article twice.
- No layout jump when images load: reserve their space.
- Works with keyboard and screen readers, and on a 360px-wide screen.
Clarifying questions
- Is a library allowed (React Query, a virtualized list), or plain React?
- Should the scroll position survive navigating to an article and back?
- Can new articles appear at the top while the reader scrolls (do cursors stay stable)?
- How many articles might a reader scroll through: hundreds, or tens of thousands?
What a strong answer covers
- An
IntersectionObserveron a sentinel element below the list, instead of scroll event math. - One place for pagination state (items, cursor, status), a guard against overlapping requests, and ignoring responses that arrive after unmount or a reset.
- Deduplicating by
idwhen pages overlap. - Distinct states: first load, loading more, error on first load, error on a later page with retry, end of feed.
- A responsive CSS grid (one column on phones, more on wide screens), images with fixed aspect ratio, and lazy loading.
- Semantic markup (
<article>, headings, links) and an accessible "Load more" button as a fallback.
Follow-ups
- Thousands of cards slow the page down: virtualize the list.
- Restore the scroll position and loaded pages after the reader comes back.
- Pull to refresh, merging new items at the top without jumping the reader.
- Test the hook with a fake
fetchArticlesthat you control.
Where it's asked
- Perplexity · Coding · Last asked Apr 202645 min · Two live coding rounds
What it tests
frontend · typescript · pagination
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
