如何在 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章