您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

对React-redux的源码分析(代码)

2024/3/9 14:38:52发布29次查看
本篇文章给大家带来的内容是关于react-redux的源码分析(代码) ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
provider
   //最后导出的是createprovider()。所以一开始storekey应该是以默认值‘store’传进去的   function createprovider(storekey = 'store', subkey) {   const subscriptionkey = subkey || `${storekey}subscription`   class provider extends component {       //设置context,能让子组件拿到store       //相当于返回 {store: this.store}       getchildcontext() {         return { [storekey]: this[storekey], [subscriptionkey]: null }       }       constructor(props, context) {         super(props, context)         //this.store = props.store         this[storekey] = props.store;       }       render() {         //只能有一个子组件         return children.only(this.props.children)       }   }      //props和context类型验证   provider.proptypes = {       store: storeshape.isrequired,       children: proptypes.element.isrequired,   }   provider.childcontexttypes = {
[storekey]: storeshape.isrequired,            [subscriptionkey]: subscriptionshape,        }                return provider    }
通常的做法是我们先通过redux创建好store,然后赋给provider组件的store属性。在provider组件内部,拿到这个store,设置为context属性,这样就能让它的所有组件都能通过context拿到store。
   <provider store={store}>       <app />   </provider>
相关推荐:
yii 的源码分析,yii源码分析
symfony2源码分析启动过程2,symfony2源码
以上就是对react-redux的源码分析(代码)的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product