forked from funmeerkats/Awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainScreenComponent.tsx
79 lines (65 loc) · 2.33 KB
/
MainScreenComponent.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, {useCallback, useMemo, useRef, useState, useEffect} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {ItemMemo} from './ItemMemo';
import {Thunk} from './Thunk';
import {Saga} from './Saga';
import {
View,
Text,
TouchableOpacity,
Button
} from 'react-native';
interface stateObj {
stateApp: stateAppObj
}
interface stateAppObj {
defaultProp: string,
[key: string]: number | string
}
const MainScreenComponent = (props: any) => {
const dispatch = useDispatch();
const stateApp = useSelector((state: stateObj): stateAppObj => state.stateApp);
const countRef = useRef(Object.keys(stateApp).length-1);
const [data, setData] = useState(11);
const {navigation} = props;
const goThunk = () => navigation.navigate('Thunk');
const addProp = useCallback((): void => {
countRef.current += 1;
dispatch({type: 'ADD_PROP', data: {[`prop_${countRef.current}`]: countRef.current}});
}, []);
const deleteProp = (): void | boolean => {
if(countRef.current === 0) return false;
dispatch({type: 'REMOVE_PROP', propName: `prop_${countRef.current}`});
countRef.current -= 1;
};
return (
<View style={{
borderWidth: 1,
borderColor: 'red',
paddingTop: 20,
flex: 1,
}}>
<TouchableOpacity onPress={goThunk}>
<Text>Go to thunk</Text>
</TouchableOpacity>
<TouchableOpacity onPress={addProp}>
<Text>ADD PROP</Text>
</TouchableOpacity>
<TouchableOpacity onPress={deleteProp}>
<Text>DELETE PROP</Text>
</TouchableOpacity>
<View style={{borderWidth: 1, borderColor: 'green', marginVertical: 20}}>
{Object.keys(stateApp) && Object.keys(stateApp).map((item, index) => {
let itemNumber: string = stateApp[item].toString();
return (
<Text key={index} style={{textAlign: 'center', color: (index === 0 ? 'red' : 'black')}}>{itemNumber}</Text>
)
})}
</View>
{/*<ItemMemo parentData={data} addProp={addProp} />*/}
{/*<Thunk />*/}
<Saga />
</View>
)
};
export {MainScreenComponent}