-
Notifications
You must be signed in to change notification settings - Fork 4
/
CounterMulti.jsx
44 lines (35 loc) · 1.38 KB
/
CounterMulti.jsx
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
import React, { Component } from 'react';
import { Counter } from './Counter';
import { connectMultireducer } from 'multireducer';
// import { multireducerBindActionCreators } from 'multireducer';
import * as CounterActions from 'redux-base/modules/multiCounter';
// function parameters are the same as in mapStateToProps from 'react-redux'
// except 1st parameter which is always multireducer key
const mapStateToProps = (key, state, ownProps) => {
//
console.log(ownProps.testProp);
return {
counter: state.multiCounters[key]
};
};
// function parameters are the same as in mapDispatchToProps from 'react-redux'
// except 1st parameter which is always multireducer key
// const mapDispatchToProps = (key, dispatch, ownProps) => {
// return multireducerBindActionCreators(key, CounterActions, dispatch);
// };
export class CounterMulti extends Component {
render() {
return (
<div>
Multicounter
<Counter {...this.props} />
</div>
);
}
}
// Can be mounted in both ways
// 1st one is more flexible, because in mapDispatchToProps function
// you can also return actions that should't be bound with multireducerKey for this component
// 2nd way - see CustomCounter.jsx example
// export default connectMultireducer(mapStateToProps, mapDispatchToProps)(CounterMulti);
export default connectMultireducer(mapStateToProps, CounterActions)(CounterMulti);