react context

在 Container.childContextTypes 中进行接口的声明,通过 getChildContext 返回更新后的state,在 Child.contextTypes 中声明要获取的接口,这样在子组件内部就能通过 this.context 获取到。通过 Context 这样一个中间对象,ChildOne 和 ChildTwo 就可以相互通信了。

最后付个链接:https://segmentfault.com/a/1190000012575622

猜你喜欢

转载自www.cnblogs.com/xuzishuai/p/9116225.html