[英]multiply 'connect' with react-redux
我想一起使用react-redux和react-geolocated 。 展位使用“命名”导出, 导出默认为 。
react-redux连接人员
const mapStateToProps = (state) => {
return {
json: state.json
}
};
const mapDispatchToProps = (dispatch) => {
return {
someLocalMethod: () => dispatch(someRemoteMethod()),
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Home)
反应地理位置相关的连接人员
export default geolocated({
positionOptions: {
enableHighAccuracy: false,
},
userDecisionTimeout: 5000
})(Home);
将这两个出口合并在一起的方式是什么?
尝试这个:
//file with geolocated stuff ------------------
...
export default geolocated({
positionOptions: {
enableHighAccuracy: false,
},
userDecisionTimeout: 5000
})(Home);
//file with react-redux connect stuff --------------
import geoHome from '/pathToGeolocatedHome';
...
export default connect(mapStateToProps, mapDispatchToProps)(geoHome)
import connect from 'react-redux-connect';
import { actionOne, actionTwo } from './actions';
export class MySmartComponent {
static mapStateToProps(state, ownProps) {
// if you need to map some data from store
return {
// some data from state here
};
}
static mapDispatchToProps(dispatch, ownProps) {
// if you need to dispatch some actions
return {
kactionOne,
actionTwo,
};
}
static mergeProps(stateProps, dispatchProps, ownProps) {
// if you want to merge props manually
return {
// ...
}
}
static connectOptions = {
// if you want to merge props manually
return {
// ...
}
}
static connectOptions = {
// if you want to merge props manually
return {
// ...
}
}
static connectOptions = {
// if you need to tweek some connect options
// e.g. pure: false
};
render() {
// return something...
}
}
// and just pass your component to `connect` function
// all settings will be taken from static props
export default connect(MySmartComponent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.