Skip to content

Commit 7d455a4

Browse files
committed
Update README.md
1 parent 867872e commit 7d455a4

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,58 @@ A collection of virtual list components, supporting the most handy features:
2828

2929
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.
3030

31+
## Caveats
32+
33+
Virtualized lists aren't appropriate for all situations. Here's some caveats:
34+
35+
- 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 an external store like Rodux.
36+
- This is a `PureComponent` which means that it will not re-render if `props` are shallow-equal. Make sure that everything your `renderItem` function depends on is passed as a prop (e.g. `extraData`) that is not `===` after updates, otherwise your UI may not update on changes. This includes the `data` prop and parent component state.
37+
- 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 and momentarily see blank content. This is a tradeoff that can be adjusted to suit the needs of each application.
38+
- 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.
39+
40+
## Example
41+
42+
```lua
43+
local React = require(...)
44+
local VirtualizedList = require(...)
45+
46+
local View = VirtualizedList.View
47+
local FlatList = VirtualizedList.FlatView
48+
49+
local e = React.createElement
50+
51+
local DATA = {
52+
{
53+
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
54+
title: 'First Item',
55+
},
56+
{
57+
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
58+
title: 'Second Item',
59+
},
60+
{
61+
id: '58694a0f-3da1-471f-bd96-145571e29d72',
62+
title: 'Third Item',
63+
},
64+
}
65+
66+
local function Item(props)
67+
return e(View, {}, {
68+
e("TextLabel", {
69+
Size = UDim2.new(1, 0, 0, 40),
70+
Text = props.title,
71+
})
72+
})
73+
end
74+
75+
local function App()
76+
return e(FlatList, {
77+
data = DATA,
78+
renderItem = Item,
79+
})
80+
end
81+
```
82+
3183
## Documentation
3284

3385
More information on the provided list components can be found at:

0 commit comments

Comments
 (0)