Redux Provider not passing down Props/State

断了今生、忘了曾经 提交于 2019-12-12 21:15:26

问题


I've created a React App using create-react-app and added Redux to it. After adding <Provider store={store} /> only the component that I pass as the argument (the main component) on connectis receiving the props/state. Why do the nested components not receive them?

I will not paste the code here because I don't know what is causing the problem. Instead, here is the link to the entire App: https://github.com/KadoBOT/Box.es


回答1:


Currently you are connecting only MainPage or TemplatePage component, depends on condition. But you dont push props down. Here are couple ways how you can get it in your child components

  1. React.cloneElement

  2. using connect > connect(mapStateToProps, mapDispatchToProps)(ChildComponent)

  3. You can pass it explicitly from MainPage or TemplatePage component <ItemView {...this.props}/> ... <ItemSidebar {...this.props}/>

Thanks



来源:https://stackoverflow.com/questions/41043122/redux-provider-not-passing-down-props-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!