File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+ import List from '../src/List' ;
3
+
4
+ interface Item {
5
+ id : number ;
6
+ height : number ;
7
+ }
8
+
9
+ const MyItem : React . FC < Item > = ( { id, height } , ref ) => {
10
+ return (
11
+ < span
12
+ ref = { ref }
13
+ style = { {
14
+ border : '1px solid gray' ,
15
+ padding : '0 16px' ,
16
+ height,
17
+ lineHeight : '30px' ,
18
+ boxSizing : 'border-box' ,
19
+ display : 'inline-block' ,
20
+ } }
21
+ >
22
+ { id }
23
+ </ span >
24
+ ) ;
25
+ } ;
26
+
27
+ const ForwardMyItem = React . forwardRef ( MyItem ) ;
28
+
29
+ const dataSource : Item [ ] = [ ] ;
30
+ for ( let i = 0 ; i < 100 ; i += 1 ) {
31
+ dataSource . push ( {
32
+ id : i ,
33
+ height : 30 + ( i % 2 ? 70 : 0 ) ,
34
+ } ) ;
35
+ }
36
+
37
+ const Demo = ( ) => {
38
+ return (
39
+ < React . StrictMode >
40
+ < div >
41
+ < h2 > Dynamic Height</ h2 >
42
+
43
+ < List
44
+ dataSource = { dataSource }
45
+ height = { 500 }
46
+ itemHeight = { 30 }
47
+ itemKey = "id"
48
+ style = { {
49
+ border : '1px solid red' ,
50
+ boxSizing : 'border-box' ,
51
+ } }
52
+ >
53
+ { item => < ForwardMyItem { ...item } /> }
54
+ </ List >
55
+ </ div >
56
+ </ React . StrictMode >
57
+ ) ;
58
+ } ;
59
+
60
+ export default Demo ;
You can’t perform that action at this time.
0 commit comments