React开发实时聊天招聘工具 -第四章 Redux
复杂以后 setState 就不太方便了
所以使用Redux来管理 React只负责View。
Store、State、Dispatch、Reducer
reducer(state,action)
{
switch(action.type){
case ...
... ...
return newAction;
}
}
·通过Reducer创建Store
·Store.dispatch(action)来修改状态
·Reducer函数接受state和action,返回新的state,可用store.subscribe监听每次修改
mapStateToProps
会订阅 Store,每当state
更新的时候,就会自动执行,重新计算 UI 组件的参数,从而触发 UI 组件的重新渲染。
mapStateToProps
的第一个参数总是state
对象,还可以使用第二个参数,代表容器组件的props
对象。
装饰器
@connect([mapStateToProps], [mapDispatchToProps], [mergeProps],[options])
mapStateToProps(state, ownProps) : stateProps
这个函数允许我们将 store 中的数据作为 props 绑定到组件上。
mapDispatchToProps(dispatch, ownProps): dispatchProps
connect 的第二个参数是 mapDispatchToProps,它的功能是,将 action 作为 props 绑定到组件上,也会成为 MyComp 的 props。
React开发实时聊天招聘工具 -第四章 Redux的更多相关文章
- React开发实时聊天招聘工具 -第三章 React基础知识回顾
function a (props) { return <h1>hello world{this.props.asd}</h1> } class a extends React ...
- React开发实时聊天招聘工具 -第六章 登陆注册(2)
1.bodyParser和cookieParser: const bodyParser = require('body-parser') const cookieParser = require( ...
- React开发实时聊天招聘工具 -第六章 登陆注册(1)
1.基于cookie的用户认证 express 依赖 cookie-parser 2.axios语法: axios.get('/data').then(res=>{ if(res.status= ...
- React开发实时聊天招聘工具 -第五章 需求分析
Axios的使用 axios.get('/data') .then(res=>{ if(res.status==200) this.setState(data:res.data) })
- React开发实时聊天招聘工具 -第一章
第一章 课程道学 6个页面 弱化css Antd-mobile作为组件库 Redux 状态管理 React-Router 路由 Axios异步请求 后端Express框架 Socket.io 数据库: ...
- React开发实时聊天招聘工具 -第二章
2-1 介绍React开发环境 npm install -g create-react-app xxx npm run eject 来配置webpack 2-2 ES6常用语法 其他 还有一些特性 ...
- react+redux+react-router+node.js 开发实时聊天App 学习记录
一.课程导学 1.React 主要解决的是UI层的问题,应用的状态需要借助Redux等状态管理. 2.前端React + antd-mobile UI组件库 + Redux 状态管理库 + Rea ...
- Vue2.5开发去哪儿网App 第四章笔记 上
一 . 组件细节知识点 1. 解决组件在h5中编码规范 例如 : table , ul , ol 等等 <table> <tbody> <row></r ...
- Vue2.5开发去哪儿网App 第四章笔记 下
1.解决非父子组件之间的传值问题 非父子组件传值(Bus/总线/发布订阅模式/观察者模式) 给 Vue类上挂在一个属性,然后创建vue实例时,实例就拥有了这个属性 Vue.prototype.bus ...
随机推荐
- Navicat: Can't create a procedure from within another stored routine
测试调用mysql的存储过程,于是用Navicat写,结果报这个错误,源代码如下: CREATE PROCEDUREQueryDate() BEGIN SELECTCURDATE(); E ...
- mysql 里面的isnull()和ifnull() is null 和 is not null
usergrade表 1.找到里面username是null的行 SELECT * FROM usergrade WHERE ISNULL(USERNAME) SELECT * FROM usergr ...
- P3162 [CQOI2012]组装
传送门 退火大法好 我并不会正解于是只好打退火了--其他没啥好讲--只要对每一种颜色开一个vector,存一下所有这个颜色的位置,判定的时候可以去所有的颜色里二分找到前缀和后缀,把和当前点距离小的加入 ...
- 支持宕机自动恢复触发一次性或周期性任务执行的组件包首次介绍-easyTask
easyTask介绍 一个方便触发一次性或周期性任务执行的工具包,支持海量,高并发,高可用,宕机自动恢复任务 使用场景 需要精确到秒的某一时刻触发任务执行.比如订单交易完成24小时后如果客户未评价,则 ...
- gRPC入门
一.gRPC简介 在介绍gRPC之前先说一下RPC(Remote Procedure Call),也叫远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.相比 ...
- Qt下存储读写应用程序设置的三种方法
一.简介 用户对应用程序经常有这样的要求:要求它能记住它的settings,比如窗口大小.位置和密码等等.有三种方法可以实现: 使用注册表: 使用配置文件(.ini): 使用自定义文件(例如.txt) ...
- poj 2349 Arctic Network(最小生成树的第k大边证明)
题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...
- [USACO 2012 Mar Gold] Large Banner
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=127 又是一道这种题目,遇到一次跪一次,这次终于硬着头皮看懂了题解,但是谢 ...
- Codeforces Round #459 (Div. 2)C. The Monster
C. The Monster time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 构造 HDOJ 5414 CRB and String
题目传送门 题意:给两个字符串s,t,可以在s字符串任意位置后面插入字符c(与前面的不同),问是否能够将s转换为t字符串 构造:首先lens > lent 或者 s[1] != t[1] 一定是 ...