Redux Provider 没有传递道具/状态 [英] Redux Provider not passing down Props/State

查看:48
本文介绍了Redux Provider 没有传递道具/状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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 connectis 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

推荐答案

目前您是 connectMainPage 或 TemplatePage 组件,取决于条件.但你不推道具.以下是如何在子组件中获取它的几种方法

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

使用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 没有传递道具/状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆