Lists: thousands of rows without jank · mid
Infinite lists: pagination, pull-to-refresh and chat lists
A production list loads pages with a cursor, guards onEndReached against double calls, resets cleanly on pull-to-refresh, ignores stale responses, removes duplicates by id, and shows footer, empty and error states.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Cursor pagination (?cursor=<token from the last page>) stays correct when the feed changes. Page/offset pagination gives duplicates or gaps when items are inserted.
- onEndReached can fire more than once (on mount for short lists, during momentum scrolling). Keep an in-flight flag and a hasMore flag. onEndReachedThreshold is in visible lengths (0.5 = half a screen from the end).
- Pull-to-refresh: refreshing + onRefresh. Reset the cursor, cancel in-flight requests (AbortController) and ignore responses from older request ids.
- Remove duplicates by id when merging pages. ListFooterComponent for the loader or retry, ListEmptyComponent for empty, an error row with retry.
- TanStack Query's useInfiniteQuery handles pages, cursors, refetch and dedupe for you.
- Chat (newest at the bottom): an inverted list, or FlashList v2 with startRenderingFromBottom + maintainVisibleContentPosition + onStartReached to load older messages without jumping.
The red pen
Common traps: mistake → fix
Mistake: "onEndReached fires once"
Fix: it can fire several times; guard it.
Mistake: "Offset pagination is fine for a live feed"
Fix: inserts shift pages and cause duplicates.
Mistake: "Refresh just refetches page 1"
Fix: also ignore the old in-flight pages, or they overwrite fresh data.
Easy to hard
Questions interviewers ask, easy to hard
- Build an infinite list for GET /orders?cursor= with pull-to-refresh, a footer loader, retry and an empty state.
- onEndReached fires twice. Fix it.
- The user pulls to refresh while page 3 is loading. What happens?
- How do you load older chat messages at the top without the list jumping?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.