Open In App

When we use ScrollView over FlatList or vice-versa ?

Last Updated : 04 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In the landscape of mobile app development, the task of displaying lists of data is commonplace. Developers often find themselves contemplating whether to employ a ScrollView or a FlatList component for this purpose. Both ScrollView and FlatList are pivotal components in widely used frameworks like React Native, each presenting its unique benefits and applicability.

ScrollView:

The ScrollView Component is an inbuilt react-native component that serves as a generic scrollable container, with the ability to scroll child components and views inside it.

When to use ScrollView?

The ScrollView loads all content, meaning the data intended for display on the screen is loaded immediately after the component is initiated. Consequently, the entire content, represented by the data list, is mounted simultaneously. Therefore, using ScrollView is not recommended when confronted with a lengthy list of a hundred or a thousand items to be showcased on the screen. Its optimal use is reserved for scenarios where the data list is relatively short or of limited size.

Flatlist:

The FlatList Component is an inbuilt react-native component that displays similarly structured data in a scrollable list. It shows only those elements that are currently being displayed on the screen.

When to use FlatList?

In contrast to ScrollView, the FlatList exclusively renders elements that are currently visible on the screen, with the default setting typically displaying around 10 items. This characteristic ensures that the performance of the application remains unaffected. Consequently, utilizing the FlatList component is recommended when presenting an extensive list of data, as it efficiently handles the rendering process without compromising application performance.

Difference between ScrollView and Flatlist

ScrollView FlatList
It does not provide any memory management. It provides automatic memory management.
It loads all the content at once. It loads content as the window scrolled.
It results in slow rendering and increased memory usage. It does not affect the rendering speed. 
It maintains the component state. It does not maintain the component state.
It renders generic content in a scrollable container. It renders a list of similar items.
Can be imported from react native as: 
import {ScrollView} from ‘react-native’;
Can be imported from React Native as: 
import {FlatList} from ‘react-native’;

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads