Base implementation for the more convenient <FlatList> and <SectionList> components, which are also better documented. In general, this should only really be used if you need more flexibility than FlatList provides, e.g. for use with immutable data instead of plain arrays.
Virtualization massively improves memory consumption and performance of large lists by maintaining a finite render window of active items and replacing all items outside of the render window with appropriately sized blank space. The window adapts to scrolling behavior, and items are rendered incrementally with low-pri (after any running interactions) if they are far from the visible area, or with hi-pri otherwise to minimize the potential of seeing blank space.
Some caveats:
Internal state is not preserved when content scrolls out of the render window. Make sure all your data is captured in the item data or external stores like Flux, Redux, or Relay.
This is a PureComponent which means that it will not re-render if props remain shallow- equal. Make sure that everything your renderItem function depends on is passed as a prop that is not === after updates, otherwise your UI may not update on changes. This includes the data prop and parent component state.
In order to constrain memory and enable smooth scrolling, content is rendered asynchronously offscreen. This means it's possible to scroll faster than the fill rate ands momentarily see blank content. This is a tradeoff that can be adjusted to suit the needs of each application, and we are working on improving it behind the scenes.
By default, the list looks for a key prop on each item and uses that for the React key. Alternatively, you can provide a custom keyExtractor prop.
NOTE: LayoutAnimation and sticky section headers both have bugs when used with this and are therefore not officially supported yet.
NOTE: removeClippedSubviews might not be necessary and may cause bugs. If you see issues with content not rendering, try disabling it, and we may change the default there.
Determines the maximum number of items rendered outside of the visible area, in units of visible lengths. So if your list fills the screen, then windowSize={21} (the default) will render the visible screen area plus up to 10 screens above and 10 below the viewport. Reducing this number will reduce memory consumption and may improve performance, but will increase the chance that fast scrolling may reveal momentary blank areas of unrendered content.
Type
Required
number
Yes
disableVirtualization
DEPRECATED: Virtualization provides significant performance and memory optimizations, but fully unmounts react instances that are outside of the render window. You should only need to disable this for debugging purposes.
Type
Required
boolean
Yes
getItem
A generic accessor for extracting an item from any sort of data blob.
Type
Required
(data: any, index: number) => ?Item
Yes
getItemCount
Determines how many items are in the data blob.
Type
Required
(data: any) => number
Yes
initialNumToRender
How many items to render in the initial batch. This should be enough to fill the screen but not much more. Note these items will never be unmounted as part of the windowed rendering in order to improve perceived performance of scroll-to-top actions.
Type
Required
number
Yes
keyExtractor
Type
Required
(item: Item, index: number) => string
Yes
maxToRenderPerBatch
The maximum number of items to render in each incremental render batch. The more rendered at once, the better the fill rate, but responsiveness my suffer because rendering content may interfere with responding to button taps or other interactions.
Render a custom scroll component, e.g. with a differently styled RefreshControl.
Type
Required
(props: Object) => React.Element
Yes
updateCellsBatchingPeriod
Amount of time between low-pri item render batches, e.g. for rendering items quite a ways off screen. Similar fill rate/responsiveness tradeoff as maxToRenderPerBatch.
Set this true while waiting for new data from a refresh.
Type
Required
[boolean]
No
removeClippedSubviews
A native optimization that removes clipped subviews (those outside the parent) from the view hierarchy to offload work from the native rendering system. They are still kept around so no memory is saved and state is preserved.
Type
Required
boolean
No
horizontal
Type
Required
[boolean]
No
data
The default accessor functions assume this is an Array<{key: string}> but you can override getItem, getItemCount, and keyExtractor to handle any type of index-based data.
Type
Required
any
No
extraData
A marker property for telling the list to re-render (since it implements PureComponent). If any of your renderItem, Header, Footer, etc. functions depend on anything outside of the data prop, stick it here and treat it immutably.