问题
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
React.cloneElement
using
connect>connect(mapStateToProps, mapDispatchToProps)(ChildComponent)You can pass it explicitly from
MainPage or TemplatePagecomponent<ItemView {...this.props}/> ... <ItemSidebar {...this.props}/>
Thanks
来源:https://stackoverflow.com/questions/41043122/redux-provider-not-passing-down-props-state