-
Notifications
You must be signed in to change notification settings - Fork 1
/
ItemMemo.tsx
52 lines (40 loc) · 1.23 KB
/
ItemMemo.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
51
52
import React, {memo as memoComp, useEffect, useCallback, useMemo, useRef, useState} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
View,
Text,
TouchableOpacity,
} from 'react-native';
interface ItemMemoProps {
parentData: number
addProp(): void;
}
const ItemMemo:React.FC<ItemMemoProps> = memoComp(({parentData, addProp}) => {
const [item, setItem] = useState(0);
const [some, setSome] = useState(0);
const itemMemo = useMemo(() => {
for(let i = 0; i < 4000000000; i++){
}
console.log('loop finished');
return item;
}, [item]);
useEffect(() => {
console.log('render memo');
});
return (
<View>
<Text>itemMemo: {itemMemo}</Text>
<Text>some: {some}</Text>
<TouchableOpacity onPress={() => setItem(item+1)}>
<Text>ADD_MEMO</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setSome(some+1)}>
<Text>ADD_SOMETHING</Text>
</TouchableOpacity>
<TouchableOpacity onPress={addProp}>
<Text>{parentData}</Text>
</TouchableOpacity>
</View>
)
});
export {ItemMemo}