Redux 总结
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(这是一个组件)
*用装饰器的方式书写:
最新文章
- 代码自定义双色title的按钮
- 第五章 springboot + mybatis(转载)
- 《深入理解Spark:核心思想与源码分析》——SparkContext的初始化(叔篇)——TaskScheduler的启动
- oracle中的sql%rowcount,sql%found、sql%notfound、sql%rowcount和sql%isopen
- AngularJS开发指南4:指令的详解
- 使用git自动将子工程发布到百度开放云上
- 【Irrlicht鬼火引擎】掌握引擎使用流程,入门程序HelloWorld
- EditPlus+MinGW搭建简易的C/C++开发环境
- 使用<;br>;标签分行显示文本
- 你不知道的JavaScript(作用域和闭包)
- 在world中批量调整图片的大小
- python 之遍历目录树(可匹配输出特定后缀的文件)
- hihoCoder 403 Forbidden 字典树
- ASP.Net Core ";The type initializer for &#39;Gdip&#39; threw an exception";
- iOS Build Apps for the World WWDC
- STM32 变量无法赋值问题
- 网站图标 favicon.ico
- SqlServer2008备份与还原(完整图示版)
- 单点登录SSO的实现原理 (转)
- November 14th, 2017 Week 46th Tuesday
热门文章
- Python学习笔记-练习编写ATM+购物车(购物商城)
- hbase报错Could not initialize class org.apache.hadoop.hbase.protobuf.ProtobufUtil
- java用freemarker实现导出word----包含图片
- Android使用ShowcaseView加入半透明操作提示图片的方法
- SolrCloud怎样创建跟新索引信息
- HttpClient 图讲解明
- android 自己定义dialog并实现失去焦点(背景透明)的功能
- less11 属性合并
- POJ1180 Batch Scheduling 解题报告(斜率优化)
- NPashaP的二分图源码部分