[Redux] Supplying the Initial State
We will learn how to start a Redux app with a previously persisted state, and how it merges with the initial state specified by the reducers.
The initial state of store is defined by the rootReducers:
const todoApp = combineReducers({
todos,
visibilityFilter,
});
And we use 'todoApp' to create store:
const store = createStore(todoApp);
So the initial state should be default value of each reducer's state:
const todos = (state = [], action) => { ...
const visibilityFilter = (state = 'SHOW_ALL', action) => { ...
If we want to show some persosted data as initial state, we can pass the persisted data as a second args to 'createStore()' function:
const persistedState = {
todos: [
{
id: 0,
text: "Redux",
completed: false
}
]
};
const store = createStore(todoApp, persistedState);
So the rules are:
- If there is persisted data you want to display, use this second args, otherwise use ES6 default param
- Once persisted data is passed in, it will overwrite the default params.
[Redux] Supplying the Initial State的更多相关文章
- [Functional Programming + React] Provide a reasonable default value for mapStateToProps in case initial state is undefined
For example we have a component, it needs to call 'react-redux' connect function. import { compose, ...
- [Redux] Accessing Dispatch and State with Redux -- connect
If you have props and actions, you want one component to access those props and actions, one solutio ...
- 从零开始搭建一个react项目
Nav logo 120 发现 关注 消息 4 搜索 从零开始搭建一个react项目 96 瘦人假噜噜 2017.04.23 23:29* 字数 6330 阅读 32892评论 31喜欢 36 项目地 ...
- [Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer
With a well defined demarcation point between Redux and our State ADT based model, hooking up to a R ...
- [Functional Programming ADT] Initialize Redux Application State Using The State ADT
Not only will we need to give our initial state to a Redux store, we will also need to be able to re ...
- 前端(十一):props、state及redux关系梳理
所谓状态机,是一种抽象的数据模型,是“事物发展的趋势”,其原理是事件驱动.广泛地讲,世界万物都是状态机. 一.状态机是一种抽象的数据模型 在react中,props和state都可以用来传递数据.这里 ...
- [React + Functional Programming ADT] Connect State ADT Based Redux Actions to a React Application
With our Redux implementation lousy with State ADT based reducers, it is time to hook it all up to a ...
- [Functional Programming ADT] Adapt Redux Actions/Reducers for Use with the State ADT
By using the State ADT to define how our application state transitions over time, we clear up the ne ...
- react+redux教程(六)redux服务端渲染流程
今天,我们要讲解的是react+redux服务端渲染.个人认为,react击败angular的真正“杀手锏”就是服务端渲染.我们为什么要实现服务端渲染,主要是为了SEO. 例子 例子仍然是官方的计数器 ...
随机推荐
- python运维开发之第二天
一.模块初识: 1.模块定义 python是由一系列的模块组成的,每个模块就是一个py为后缀的文件,同时模块也是一个命名空间,从而避免了变量名称冲突的问题.模块我们就可以理解为lib库,如果需要使用某 ...
- Xcode-01ARC / Block
1.nonatomic 2.assign 3.strong 4.weak 5.instancetype 6.@class @property 使部分类在编译时不使用ARC -(可以让这们支持 reta ...
- spring与mybatis,strut2整合连接sqlserver不的不说的那点事儿
今天在通过spring与mybatis整合中,想连接下公司用的sqlserver数据库,结果使用Junit测发现没连上,于是就有了下面的问题: 准备工作都已经做好了 web中spring的监听配置了 ...
- sqlserver 字符串处理函数解释
1.ASCII()返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用‘’括起来,但含其它字符的字符串必须用‘’括起来使用,否则会出错.2.CHAR()将ASCII ...
- [BZOJ 1058] [ZJOI2007] 报表统计 【平衡树】
题目链接:BZOJ - 1058 题目分析 这道题看似是需要在序列中插入一些数字,但其实询问的内容只与相邻的元素有关. 那么我们只要对每个位置维护两个数 Ai, Bi, Ai 就是初始序列中 i 这个 ...
- 通过使用CyclicBarrier来计算Matrix中最大的值
import java.util.Random; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Exec ...
- [SQL Server]一次执行资料夹内的.sql 指令码
原文:[SQL Server]一次执行资料夹内的.sql 指令码 初始资料库时,我们Developers们会准备很多.sql指令码来建立资料表.检视甚至初始资料,那麽要怎麽一次执行资料夹内的*.sql ...
- 使用maven profile实现多环境可移植构建
mvn clean package -Pproduction即构建出生产环境需要的war包 mvn tomcat:redeploy -Ptest 即发布到测试环境 在开发过程中,我们的软件会面对不同的 ...
- IPCS资源
ipcrm用法 ipcrm -M shmkey 移除用shmkey创建的共享内存段 ipcrm -m shmid 移除用shmid标识的共享内存段 ipcrm -Q msgkey 移除用ms ...
- ANDROID 中UID与PID的作用与区别
PID:为Process Identifier, PID就是各进程的身份标识,程序一运行系统就会自动分配给进程一个独一无二的PID.进程中止后PID被系统回收,可能会被继续分配给新运行的程序,但是在a ...