-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (44 loc) · 976 Bytes
/
index.js
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
import React from 'react'
import { Provider, connect } from './react-redux/src'
import { createStore } from './redux/src'
import rootReducer from './reducers'
const store = createStore(rootReducer)
function Child(props) {
return <div>
<div>name: {props.name}</div>
<div>age: {props.age}</div>
<button onClick={() => props.dispatch({
type: 'CHANGE_NAME',
data: Math.random()
})}
>
change name
</button>
<button onClick={() => props.dispatch({
type: 'CHANGE_AGE',
data: Math.random()
})}
>
change age
</button>
</div>
}
const mapStateToProps = state => {
return {
name: state.name,
age: state.age
}
}
const mapDispatchToProps = dispatch => ({
// onClick: () => dispatch()
})
const ConnectChild = connect(
mapStateToProps,
// mapDispatchToProps
)(Child)
function Demo() {
return <Provider store={store}>
<ConnectChild />
</Provider>
}
export default Demo;