看网上讲解react-redux中Provider的实现原理,都是采用如下方案
为何在Provider中定义属性和方法
static childContextTypes = {
store: PropTypes.object,
}
getChildContext() {
return { store: this.store }
}
子组件中定义如下属性,就可以通过this.context。获取到上下文
static contextTypes = {
store: PropTypes.object,
}
为什么不使用React提供的context属性,来实现react-redux中Provider?