โ† React Native
#3 most askedVery commonEasyLists & performance

FlatList vs ScrollView

๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

You need to show 5,000 messages. Why use FlatList instead of ScrollView, and how do you keep it smooth?

๐Ÿ”ฎ Predict the output

// A list "virtualizer": which rows render for this scroll position?
const rowHeight = 50, screenHeight = 300, buffer = 2;
function visibleRows(scrollY, total) {
  const first = Math.max(0, Math.floor(scrollY / rowHeight) - buffer);
  const last = Math.min(total - 1, Math.ceil((scrollY + screenHeight) / rowHeight) + buffer);
  return [first, last];
}
console.log(visibleRows(0, 5000), visibleRows(10000, 5000));

๐ŸŽค Answer it out loud, then check yourself

Say your answer as if the interviewer is listening (30โ€“90 seconds). Then reveal what a strong answer covers and tick what you said.

    Answer out loud first, then compare.
    Want to rehearse it?
    Answer this to the AI interviewer and get a verdict โ†’