问题描述
我使用 create-react-app 创建了一个 React 应用程序并将 Redux 添加到其中.添加 <Provider store={store}/>
后,只有我在 connect
上作为参数传递的组件(主要组件)正在接收道具/状态.为什么嵌套组件不接收它们?
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 connect
is receiving the props/state.Why do the nested components not receive them?
我不会在这里粘贴代码,因为我不知道是什么导致了问题.相反,这里是整个应用程序的链接:https://github.com/KadoBOT/Box.es
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
推荐答案
目前您是 connect
仅 MainPage 或 TemplatePage
组件,取决于条件.但你不推道具.以下是如何在子组件中获取它的几种方法
Currently you are connect
ing 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
使用connect
> connect(mapStateToProps, mapDispatchToProps)(ChildComponent)
您可以从 MainPage 或 TemplatePage
组件显式传递它<ItemView {...this.props}/>... <ItemSidebar {...this.props}/>
You can pass it explicitly from MainPage or TemplatePage
component<ItemView {...this.props}/> ... <ItemSidebar {...this.props}/>
谢谢
这篇关于Redux Provider 没有传递道具/状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!