如何在 React 中更新父级的状态? - How can I update the parent's state in React?

问题:

My structure looks as follows:我的结构如下:

Component 1

 - |- Component 2


 - - |- Component 4


 - - -  |- Component 5

Component 3

Component 3 should display some data depending on state of Component 5.组件 3 应根据组件 5 的状态显示一些数据。

Since props are immutable, I can't simply save its state in Component 1 and forward it, right?由于 props 是不可变的,我不能简单地将它的状态保存在组件 1 中并转发它,对吗? And yes, I've read about Redux , but I don't want to use it.是的,我读过Redux ,但我不想使用它。 I hope that it's possible to solve it just with react.我希望可以通过反应来解决它。 Am I wrong?我错了吗?


解决方案:

参考一: https://en.stackoom.com/question/2P6r7
参考二: https://stackoom.com/question/2P6r7
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章