Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In react native is a List or a ScrollView better?

Tags:

react-native

I'm working on a chat like application and I have seen examples using ListView and ScrollView. What are the advantages of either? I need to render different looking items through out the chat (inputs vs. responses OR text vs. images). Does one handle this case better?

like image 909
Ben Avatar asked May 25 '17 13:05

Ben


1 Answers

I think your question is "ScrollView vs FlatList - which one to use"?

According to React-Native docs:

ScrollView vs FlatList - which one to use?

ScrollView simply renders all its react child components at once. That makes it very easy to understand and use.

On the other hand, this has a performance downside. Imagine you have a very long list of items you want to display, maybe several screens worth of content. Creating JS components and native views for everythign all at once, much of which may not even be shown, will contribute to slow rendering and increased memory usage.

This is where FlatList comes into play. FlatList renders items lazily, just when they are about to appear, and removes items that scroll way off screen to save memory and processing time.

FlatList is also handy if you want to render separators between your items, multiple columns, infinite scroll loading, or any number of other features it supports out of the box.

I would use FlatList. This is what u need. It's more effective & lazy loads your data only when needed.

like image 178
atlanteh Avatar answered Sep 20 '22 14:09

atlanteh