-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.tsx
96 lines (88 loc) · 2.69 KB
/
app.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React from "react";
import { useDispatch, useSelector } from "react-redux";
const increment1 = () => (dispatch, getState) => {
dispatch({ type: "INCREMENT" });
};
const increment2 = () => (dispatch, getState) => {
dispatch({ type: "INCREMENT" });
dispatch({ type: "INCREMENT" });
dispatch({ type: "INCREMENT" });
dispatch({ type: "INCREMENT" });
};
const increment3 = () => async (dispatch, getState) => {
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
};
const increment4 = () => async (dispatch, getState) => {
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
};
const increment5 = () => async (dispatch, getState) => {
await new Promise((resolve) => setTimeout(resolve, 1));
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
};
const increment6 = () => async (dispatch, getState) => {
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
await new Promise((resolve) => setTimeout(resolve, 1));
dispatch({ type: "INCREMENT" });
console.log(getState());
dispatch({ type: "INCREMENT" });
console.log(getState());
};
const App = () => {
console.log("render");
const dispatch = useDispatch();
const value = useSelector((state: any) => state.value);
const style = {
marginTop: "10px",
fontSize: "40px",
};
return (
<div
style={{ display: "flex", flexDirection: "column", alignItems: "center" }}
>
<button style={style} onClick={() => dispatch(increment1())}>
dispatch 1
</button>
<button style={style} onClick={() => dispatch(increment2())}>
dispatch 2
</button>
<button style={style} onClick={() => dispatch(increment3())}>
dispatch 3
</button>
<button style={style} onClick={() => dispatch(increment4())}>
dispatch 4
</button>
<button style={style} onClick={() => dispatch(increment5())}>
dispatch 5
</button>
<button style={style} onClick={() => dispatch(increment6())}>
dispatch 6
</button>
<div style={style}>data: {JSON.stringify(value)}</div>
</div>
);
};
export default App;