【问题标题】:How to get parent props from descendent component?如何从后代组件获取父道具?
【发布时间】:2020-03-26 15:53:56
【问题描述】:

我的结构如下所示。我需要从 component5 中读取 component1 的 props。怎么做?谢谢。

Component 1  

  |- Component 2

    |- Component 4

      |- Component 5

【问题讨论】:

标签: reactjs


【解决方案1】:

这里有两个主要选择:

而不同的需求你可以选择Context or Redux to use

【讨论】:

    【解决方案2】:

    你可以在 react 或 redux 中使用上下文

    上下文:https://reactjs.org/docs/context.html

    还有redux库:https://redux.js.org/

    【讨论】:

      猜你喜欢
      • 2019-08-30
      • 2021-07-31
      • 1970-01-01
      • 2019-05-24
      • 1970-01-01
      • 2021-09-19
      • 2020-07-30
      • 2021-07-22
      • 1970-01-01
      相关资源
      最近更新 更多