-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
72 lines (69 loc) · 1.87 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { FC } from 'react'
import { connect } from 'react-redux'
import { RouteComponentProps, withRouter } from 'react-router-dom'
import { RootDispatch, RootState } from '@/store'
import './index.less'
const mapState = (state: RootState) => ({
state: state.demo,
})
const mapDispatch = (dispatch: RootDispatch) => ({
dispatch: dispatch.demo,
})
export type DemoProps = ReturnType<typeof mapState> &
ReturnType<typeof mapDispatch> &
RouteComponentProps
const Demo: FC<DemoProps> = ({ state, dispatch, history }) => {
return (
<div className="demo">
<div className="demo-route">当前路由:{history.location.pathname}</div>
<div>
<button
className="demo-button"
onClick={() => {
dispatch.SET_COUNT(state.count + 1)
}}
>
Add count
</button>
<button
className="demo-button"
onClick={() => {
dispatch.SET_COUNT(state.count - 1)
}}
>
Minus Count
</button>
<div className="demo-counter">counter {state.count}</div>
</div>
<button
className="demo-button"
onClick={async () => {
await dispatch.getPlayers()
}}
>
Fetch Players
</button>
<button
className="demo-button"
onClick={async () => {
await dispatch.getTestAPI()
}}
>
Fetch Test API
</button>
{state.players.length ? (
<ol>
{state.players.map((player) => (
<div className="demo-player" key={player.id}>
{player.id}, {player.first_name}
</div>
))}
</ol>
) : null}
{state.testAPTResult ? (
<pre>{JSON.stringify(state.testAPTResult, null, 2)}</pre>
) : null}
</div>
)
}
export default connect(mapState, mapDispatch)(withRouter(Demo))