Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redux 通过组合连接函数重用MapStateTrops_Redux_React Redux - Fatal编程技术网

Redux 通过组合连接函数重用MapStateTrops

Redux 通过组合连接函数重用MapStateTrops,redux,react-redux,Redux,React Redux,例如,我遇到这样的情况:三个组件使用来自存储的相同状态,以及它们唯一的状态 我想重构它,所以我不会重复工作,通过这样做: const sharedMapStateToProps = state => ({ sharedValue1: state.sharedValue1, sharedValue2: state.sharedValue2, sharedValue3: state.sharedValue3, }); const uniqeMapStateToProps = st

例如,我遇到这样的情况:三个组件使用来自存储的相同状态,以及它们唯一的状态

我想重构它,所以我不会重复工作,通过这样做:

const sharedMapStateToProps = state => ({
  sharedValue1: state.sharedValue1,
  sharedValue2: state.sharedValue2,
  sharedValue3: state.sharedValue3,
});

const uniqeMapStateToProps = state => ({
  uniqueValue1: state.uniqueValue1,
  uniqueValue2: state.uniqueValue2,
});

compose(
  connect(sharedMapStateToProps),
  connect(uniqeMapStateToProps)
)(SomeComponent)
有没有办法重用和组合
mapStateToProps
/
mapDispatchToProps
/
mergeProps
功能?

您尝试过吗

compose(
  connect(state => ({ ...sharedMapStateToProps(state), ...uniqeMapStateToProps(state) })),
)(SomeComponent)

我尝试了类似的方法:
const-mapStateToProps=state=>({
`…sharedMapStateToProps(state),`uniqueValue1:state.uniqueValue1,`uniqueValue2:state.uniqueValue2,`
})`