FlashcardNot attempted
Infinite scroll checklist
Recall it before you reveal
You are adding infinite scroll to a list or table. What is on your checklist?
Space to reveal
Show answer & explanation
- One trigger: a sentinel row watched by a single
IntersectionObserver(root= the scroll container if there is one,rootMarginto prefetch). No scroll listener. - Guard with current state: "load more" is ignored unless idle and
hasMore; do it in a reducer or ref, not a value captured in a closure. - `hasMore` in one unit: rows loaded < total, or "the server returned a next cursor". Stop observing at the end.
- Short first page: re-observing a visible sentinel fires straight away, so re-attach after each load and the next page follows.
- Filter / sort change: abort the in-flight request, reset to page 1, clear rows.
- Stable order: offset paging needs a total order (tie-break on id), or use cursor pagination when rows are inserted live.
- States: loading, error with retry, empty, end of list. Keys from data ids.
- Scale and a11y: virtualise thousands of rows; announce loads in a
role="status"region; offer a "Load more" button fallback.