[英]Chaining redux connect mapStateToProps , to access props inside mapDispatchToProps
In order to access to the props
of the component inside the mapDispatchToProps
i chained my connect like so 为了访问
mapDispatchToProps
内部的组件的props
,我像这样将我的连接链接mapDispatchToProps
export default connect(mapStateToProps, null)(connect(mapStateToProps, mapDispatchToProps)(MyComponent));
And then i manage to access to the props inside the mapDispatchToProps like so 然后我设法像这样访问mapDispatchToProps内部的道具
const mapDispatchToProps = (dispatch,ownProps) => {
const myProp = ownProps.theProp
}
Is it a bad things to do ? 这是一件坏事吗? Any alternative exists ?
有其他选择吗?
Is it a bad things to do?
这是一件坏事吗?
IMO, It is certainly bad. 海事组织,这肯定是不好的。
connect()
is an HOC. connect()
是一个HOC。 connect(...)(connect(...)(MyComponent))
is redundant. connect(...)(connect(...)(MyComponent))
是多余的。
Any alternative exists ?
有其他选择吗?
Use mergeProps
instead or break the components properly and use redux-saga
to use a common interaction point (the redux store). 请改用
mergeProps
或适当地破坏组件,并使用redux-saga
使用公共交互点(redux存储)。
The correct way to connect mapDispatch to props and mapStateToProps is like this: 将mapDispatch连接到props和mapStateToProps的正确方法是这样的:
export default connect(mapStateToProps, mapDispatchToProps)(MetaDataTaggingApp);
Also I don't think you should have to access props in mapDispatchToProps. 另外,我认为您不必在mapDispatchToProps中访问道具。 mapDispatchToProps is basically just telling your component which dispatch actions it's allowed to use.
mapDispatchToProps基本上只是告诉您的组件允许使用哪些调度动作。
const mapDispatchToProps = {
aReduxAction,
anotherReduxAction
}
If you need to pass props into these dispatches, it should be when you are invoking them. 如果您需要将道具传递到这些调度中,那应该是在调用它们时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.