Redux Provider not passing down Props/State

2019-07-21 18:32发布

问题:

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