FlashList. You can try out FlashList by changing the component name.
Basic Example
Migration from FlatList
To avoid common pitfalls, follow these steps for migrating fromFlatList:
- Change component name: Simply replace
FlatListwithFlashList - Remove
keyprops: Scan yourrenderItemhierarchy for explicitkeyprop definitions and remove them. If you’re doing a.map(), use theuseMappingHelperhook - Handle component state: Check your
renderItemhierarchy for components that useuseStateand verify whether that state needs to be reset when a different item is passed (see Recycling) - Specify item types: If your list has heterogeneous views, pass their types using
getItemTypeto improve performance - Test in release mode: Do not test performance with JS dev mode on. FlashList can appear slower in dev mode due to a smaller render buffer
- Memoize props: Memoizing props passed to FlashList is more important in v2 to prevent unnecessary re-renders
- Add
keyExtractor: This is important to prevent glitches due to item layout changes when scrolling upwards - Use new hooks: Learn about
useLayoutStateanduseRecyclingStatefor simplified state management - Nest FlashLists: When nesting horizontal FlashLists in vertical lists, we highly recommend the vertical list to be FlashList too for better optimization
Core Props
renderItem
Takes an item from
data and renders it into the list.item(Object): The item fromdatabeing renderedindex(number): The index corresponding to this item in thedataarraytarget(string): The render target for the item:Cell- For your list itemMeasurement- For size measurement (won’t be visible)StickyHeader- For sticky headers (use this to change appearance)
extraData(Object): The sameextraDataprop passed to FlashList
data
For simplicity, data is a plain array of items of a given type.
getItemType
Allows developers to specify item types for improved recycling when you have different types of items in the list.
0. If you don’t want to change type for certain items, just return undefined.
Example:
keyExtractor
Used to extract a unique key for a given item at the specified index.
keyExtractor is also necessary when doing layout animations to uniquely identify animated components.
horizontal
If
true, renders items next to each other horizontally instead of stacked vertically.numColumns
Multiple columns can only be rendered with
horizontal={false} and will zig-zag like a flexWrap layout.Items should all be the same height - masonry layouts require the
masonry prop.ListHeaderComponent
Rendered at the top of all the items. Can be a React Component or a React element.
ListFooterComponent
Rendered at the bottom of all the items. Can be a React Component or a React element.
ListEmptyComponent
Rendered when the list is empty. Can be a React Component or a React element.
ItemSeparatorComponent
Rendered in between each item, but not at the top or bottom. By default,
leadingItem and trailingItem props are provided.contentContainerStyle
You can use this to apply padding to the whole content itself.
extraData
A marker property for telling the list to re-render (since it implements
PureComponent).renderItem, Header, Footer, etc. functions depend on anything outside of the data prop, stick it here and treat it immutably.
Scroll Events
onEndReached
Called once when the scroll position gets within
onEndReachedThreshold of the rendered content.onEndReachedThreshold
How far from the end (in units of visible length of the list) the bottom edge must be to trigger
onEndReached.0.5 will trigger onEndReached when the end of the content is within half the visible length of the list.
onStartReached
Called once when the scroll position gets within
onStartReachedThreshold of the start of the content.onStartReachedThreshold
How far from the start (in units of visible length) the top edge must be to trigger
onStartReached.Lifecycle Callbacks
onLoad
Raised once the list has drawn items on the screen.
elapsedTimeInMs which is the time it took to draw the items. FlashList doesn’t render items in the first cycle - items are drawn after it measures itself at the end of first render.
This event is not fired if
ListEmptyComponent is rendered.onCommitLayoutEffect
Called before layout is committed. Can be used to measure list and make changes before paint.
onViewableItemsChanged
Called when the viewability of rows changes, as defined by the
viewabilityConfig prop.If you are tracking the time a view becomes (non-)visible, use the
timestamp property. We make no guarantees that viewability callbacks will be invoked immediately.viewabilityConfig
Default configuration for determining whether items are viewable.
minimumViewTime(number): Minimum time (in ms) that an item must be physically viewable before the callback fires. Default is250viewAreaCoveragePercentThreshold(number): Percent of viewport (0-100) that must be covered for a partially occluded item to count as viewableitemVisiblePercentThreshold(number): Percent of the item that is visible (0-100)waitForInteraction(boolean): Nothing is considered viewable until the user scrolls orrecordInteractionis called
Advanced Props
maintainVisibleContentPosition
Configuration for maintaining scroll position when content changes. Enabled by default.
overrideItemLayout
This method can be used to change column span of an item in grid layouts.
numColumns > 1) and want a few items to be bigger than the rest.
CellRendererComponent
Each cell is rendered using this element. The root component should always be a
CellContainer (the default).props are passed to the returned CellContainer.
Example with Reanimated:
Hooks
useLayoutState
useState but communicates the change in state to FlashList. Useful if you want to resize a child component based on local state.
Example:
useRecyclingState
useState but accepts a dependency array. On change of deps, the state gets reset without an additional setState call. Useful for maintaining local item state. Also includes useLayoutState functionality.
Example:
useMappingHelper
.map() in your render methods. This ensures optimal performance by providing consistent keys that work with the recycling system.
Parameters:
index(number): The index of the item in the arrayitemKey(string | number | bigint): A unique identifier for the item
Use
useMappingHelper whenever you need to map over arrays inside FlashList item components to ensure proper recycling.useFlashListContext
ref of FlashList and its ScrollView. Ideal for use within child components or CellRendererComponent.
FlashList Methods
These methods are available on the FlashList ref:scrollToIndex
scrollToItem
scrollToOffset
scrollToEnd
scrollToTop
prepareForLayoutAnimationRender
getVisibleIndices
Unsupported FlatList Props
The followingFlatList props are not implemented:
columnWrapperStyledebuglistKeydisableVirtualizationgetItemLayoutinitialNumToRendermaxToRenderPerBatchupdateCellsBatchingPeriodonScrollToIndexFailedwindowSize