我有一个带有孩子的父组件,又有另一个孩子,依此类推。
Parent
| Child A
| Child B
| Child C
...
| Child G
如何在Child G
中调用Parent
中的方法而不为此传递道具?我可以为此使用Ref
吗?
答案 0 :(得分:1)
If you don't want to pass props, you can use React's Context API
I made a working example for you.
Hope this helps, if you need more explanation, just let me know!