@@ -40,44 +40,67 @@ Virtualized lists aren't appropriate for all situations. Here's some caveats:
40
40
## Example
41
41
42
42
``` lua
43
- local React = require (... )
44
- local VirtualizedList = require (... )
43
+ local ReplicatedStorage = game :GetService (" ReplicatedStorage" )
44
+ local HttpService = game :GetService (" HttpService" )
45
+ local Players = game :GetService (" Players" )
46
+
47
+ local Packages = ReplicatedStorage .Packages
48
+
49
+ local React = require (Packages .React )
50
+ local ReactRoblox = require (Packages .ReactRoblox )
51
+ local VirtualizedList = require (Packages .VirtualizedList )
45
52
46
53
local View = VirtualizedList .View
47
- local FlatList = VirtualizedList .FlatView
54
+ local FlatList = VirtualizedList .FlatList
48
55
49
56
local e = React .createElement
50
57
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
- }
58
+ local ITEM_COUNT = 10 _000
59
+ local DATA = table .create (ITEM_COUNT )
60
+
61
+ for i = 1 , ITEM_COUNT do
62
+ DATA [i ] = {
63
+ id = HttpService :GenerateGUID (false ),
64
+ title = ` Item {i}` ,
65
+ }
66
+ end
65
67
66
68
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
- })
69
+ return e (View , {}, {
70
+ ItemText = e (" TextLabel" , {
71
+ Size = UDim2 .new (1 , 0 , 0 , 40 ),
72
+ Text = props .title ,
73
+ }),
74
+ })
73
75
end
74
76
75
77
local function App ()
76
- return e (FlatList , {
78
+ return e (" ScreenGui" , {
79
+ ResetOnSpawn = false ,
80
+ ZIndexBehavior = Enum .ZIndexBehavior .Sibling ,
81
+ }, {
82
+ Background = e (" Frame" , {
83
+ AnchorPoint = Vector2 .new (0.5 , 0.5 ),
84
+ Position = UDim2 .fromScale (0.5 , 0.5 ),
85
+ Size = UDim2 .fromScale (0.25 , 0.4 ),
86
+ }, {
87
+ List = e (FlatList , {
77
88
data = DATA ,
78
- renderItem = Item ,
79
- })
89
+ renderItem = function (entry )
90
+ return e (Item , {
91
+ title = entry .item .title ,
92
+ })
93
+ end ,
94
+ keyExtractor = function (entry )
95
+ return entry .id
96
+ end ,
97
+ }),
98
+ }),
99
+ })
80
100
end
101
+
102
+ local root = ReactRoblox .createRoot (Instance .new (" Folder" ))
103
+ root :render (ReactRoblox .createPortal (e (App ), Players .LocalPlayer .PlayerGui ))
81
104
```
82
105
83
106
## Documentation
0 commit comments