admin管理员组文章数量:1293531
Saying i have a Container
connected to redux via:
const mapStateToProps = ({ MyReducer }) => ({
myProp: MyReducer.myProp
});
Is it possible to force the value of myProp by the parent (override redux)?
I've tried:
<Container myProp={"notReduxValue"}/>
But mapStateToProps
overrides the provided value.
NOTE: I can't change the container, my question is if it can be done via the parent only.
(Of course this implies a bad state design but unfortunately it has e to that)
Thanks
Saying i have a Container
connected to redux via:
const mapStateToProps = ({ MyReducer }) => ({
myProp: MyReducer.myProp
});
Is it possible to force the value of myProp by the parent (override redux)?
I've tried:
<Container myProp={"notReduxValue"}/>
But mapStateToProps
overrides the provided value.
NOTE: I can't change the container, my question is if it can be done via the parent only.
(Of course this implies a bad state design but unfortunately it has e to that)
Thanks
Share asked Oct 2, 2017 at 10:25 DanielDaniel 6,4917 gold badges38 silver badges63 bronze badges1 Answer
Reset to default 10mapStateToProps
accepts two arguments. So I guess you could override it by:
const mapStateToProps = ({ MyReducer }, { myProp }) => ({
myProp: myProp || MyReducer.myProp,
})
In case you want to override myProp
in an upper level, you can use connect
's mergeProps
to do so (as @OrB also described).
const mapStateToProps = ({ MyReducer }, { myProp }) => ({
myProp: MyReducer.myProp,
})
const mapDispatchToProps = () => ({ ... })
const mergeProps = (stateProps, dispatchProps, ownProps) => ({
... // make your changes here
})
const ConnectedContainer = connect(
mapStateToProps,
mapDispatchToProps,
mergeProps
)(Container)
本文标签: javascriptReactoverride redux prop by parentStack Overflow
版权声明:本文标题:javascript - React - override redux prop by parent - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741581361a2386587.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论