forked from weird94/react-typed-recyclelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
50 lines (43 loc) · 1.24 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { memo } from 'react';
import List, { CellProps, CellDatas } from '../../src/index';
import useStoreState from '../../src/useStoreState';
import ReactDOM from 'react-dom';
const cellStyle: React.CSSProperties = {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column'
};
const Cell = memo((props: CellProps<{ name: string }>) => {
const [active, setActive] = useStoreState(false, 'active', props);
const { style, index } = props;
const bgColor = index % 2 === 0 ? 'white' : 'yellow';
return (
<div
style={{ ...cellStyle, ...style, backgroundColor: bgColor }}
onClick={() => setActive(!active)}
>
<div
style={{
color: active ? 'red' : 'black',
fontWeight: active ? 'bolder' : 'normal'
}}
>
[{index}] active: <span>{active + ''}</span>
</div>
</div>
);
});
const cellData: CellDatas<{ name: string }> = Array(1000)
.fill(1)
.map((_, i) => {
return {
height: 100,
data: { name: `name` },
Component: Cell
};
});
const Demo = () => {
return <List height={screen.height} width={screen.width} cellData={cellData} />;
};
ReactDOM.render(<Demo />, document.getElementById('root'));