1.redux:

function reducer(state=-,action)

{

switch(action.type)

{

case '':

return ...

case '':

return ...

default:

return ...

}

}

const store = createStore(reducer)

function listener(){

const current = store.getState()

console.log(current);

}

store.subscribe(listener)

store.dispatch({type:'...'})

2.redux配合react一起使用:

index.js

function render()

{

ReactDom.render(<App store={store}/>,document.getElementById('root'))

}

store.subscribe(render)

App.js: 里面是组件和store

index.reducer.js 里面是reducer 和 actioncreator

3.使用redux-thunk让redux处理异步:

一.安装redux-thunk

二.使用applyMiddleware开启thunk中间件

三.Action可以返回函数,使用dispatch提交action

首先开启中间件:

引入thunk:

然后创建store

调试工具:

4.使用react-redux:

npm install react-redux –save

忘记subscribe,只使用reducer、action、和dispatch

·Provier组件在应用最外层,传入store即可,只用一次

·Connect负责从外部获取组建需要的参数

index.js:

App.js(这是一个组件)

*用装饰器的方式书写:

最新文章

  1. 代码自定义双色title的按钮
  2. 第五章 springboot + mybatis(转载)
  3. 《深入理解Spark:核心思想与源码分析》——SparkContext的初始化(叔篇)——TaskScheduler的启动
  4. oracle中的sql%rowcount,sql%found、sql%notfound、sql%rowcount和sql%isopen
  5. AngularJS开发指南4:指令的详解
  6. 使用git自动将子工程发布到百度开放云上
  7. 【Irrlicht鬼火引擎】掌握引擎使用流程,入门程序HelloWorld
  8. EditPlus+MinGW搭建简易的C/C++开发环境
  9. 使用&lt;br&gt;标签分行显示文本
  10. 你不知道的JavaScript(作用域和闭包)
  11. 在world中批量调整图片的大小
  12. python 之遍历目录树(可匹配输出特定后缀的文件)
  13. hihoCoder 403 Forbidden 字典树
  14. ASP.Net Core &quot;The type initializer for &#39;Gdip&#39; threw an exception&quot;
  15. iOS Build Apps for the World WWDC
  16. STM32 变量无法赋值问题
  17. 网站图标 favicon.ico
  18. SqlServer2008备份与还原(完整图示版)
  19. 单点登录SSO的实现原理 (转)
  20. November 14th, 2017 Week 46th Tuesday

热门文章

  1. Python学习笔记-练习编写ATM+购物车(购物商城)
  2. hbase报错Could not initialize class org.apache.hadoop.hbase.protobuf.ProtobufUtil
  3. java用freemarker实现导出word----包含图片
  4. Android使用ShowcaseView加入半透明操作提示图片的方法
  5. SolrCloud怎样创建跟新索引信息
  6. HttpClient 图讲解明
  7. android 自己定义dialog并实现失去焦点(背景透明)的功能
  8. less11 属性合并
  9. POJ1180 Batch Scheduling 解题报告(斜率优化)
  10. NPashaP的二分图源码部分