将 'connect' 与 react-redux 相乘
multiply 'connect' with react-redux
我想将 react-redux 和 react-geolocated 一起使用。
展位使用 'named' 导出 默认导出 .
react-redux 连接人员
const mapStateToProps = (state) => {
return {
json: state.json
}
};
const mapDispatchToProps = (dispatch) => {
return {
someLocalMethod: () => dispatch(someRemoteMethod()),
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Home)
react-geolocated 相关连接人员
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);
我想将 react-redux 和 react-geolocated 一起使用。 展位使用 'named' 导出 默认导出 .
react-redux 连接人员
const mapStateToProps = (state) => {
return {
json: state.json
}
};
const mapDispatchToProps = (dispatch) => {
return {
someLocalMethod: () => dispatch(someRemoteMethod()),
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Home)
react-geolocated 相关连接人员
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);