FlatList component
In React Native, to create a flat list, you use the FlatList
component, which is an efficient way to render lists of items. It handles performance optimizations like lazy loading and recycling views out of the box.
Here’s a basic example of how to implement a FlatList
:
Key Concepts:
data
: The list of items to display, an array of objects.renderItem
: A function that takes an item from thedata
array and returns a React component to render.keyExtractor
: A function that extracts a unique key from each item. This is important for performance and avoiding issues with re-rendering.
Additional Props:
horizontal={true}
: Set the list to scroll horizontally.numColumns={2}
: Display multiple items in a grid (e.g., 2 columns).onEndReached
: Callback when the list reaches the end (useful for pagination).
Let me know if you'd like to dive deeper into any aspect! FlatList Horizontal Scrolling