-
Notifications
You must be signed in to change notification settings - Fork 1
/
Saga.tsx
54 lines (44 loc) · 1.45 KB
/
Saga.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
import React, {useEffect} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {actionCreatorForSaga} from './asyncReducer';
import {
View,
Text,
TouchableOpacity,
} from 'react-native';
let asyncCount = 0;
let notAsyncCount = 0;
interface stateObj {
asyncDataSaga: asyncDataSagaObj
}
interface asyncDataSagaObj {
asyncCount: number
notAsyncCount: number
}
const Saga = (props: object) => {
const dispatch = useDispatch();
const sagaData = useSelector((state: stateObj): asyncDataSagaObj => state.asyncDataSaga);
useEffect(() => {
console.log('render saga', sagaData);
}, [sagaData]);
const actionClick = () => {
asyncCount += 10;
dispatch(actionCreatorForSaga('SAGA_REQUEST', {async: true, count: asyncCount}));
};
const actionNotAsyncClick = () => {
notAsyncCount += 20;
dispatch(actionCreatorForSaga('SAGA_REQUEST', {async: false, count: notAsyncCount}));
};
return (
<View style={{marginVertical: 20, borderWidth: 1, borderColor: 'blue'}}>
<Text>Saga</Text>
<TouchableOpacity onPress={actionClick}>
<Text style={{textAlign: 'center'}}>Send async Saga</Text>
</TouchableOpacity>
<TouchableOpacity onPress={actionNotAsyncClick}>
<Text style={{textAlign: 'center'}}>Send not async Saga</Text>
</TouchableOpacity>
</View>
)
};
export {Saga}