如何从子孙组件中获取父道具?

时间:2019-12-02 02:57:02

标签: reactjs

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

Component 1  

  |- Component 2

    |- Component 4

      |- Component 5

2 个答案:

答案 0 :(得分:1)

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

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

和redux库:https://redux.js.org/

答案 1 :(得分:1)

您在这里有两个主要选择:

根据需要,您可以选择Context or Redux to use