We'll learn how to start a Redux app with a previously persisted state, and how it merges with the initial state specifi Ed by the reducers.
The initial state of store was defined by the Rootreducers:
Const TODOAPP = combinereducers ({ todos, visibilityfilter,});
And we use the ' Todoapp ' to create store:
Const STORE = createstore (Todoapp);
So the initial state should is default value of each reducer ' s state:
Const TODOS = (state = [], action) += (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: [ { 0, "Redux", false } = CreateStore (Todoapp, persistedstate);
So the rules is:
- If there is persisted data want to display, use this second args, otherwise use ES6 default param
- Once persisted data is passed in, it would overwrite the default params.
[Redux] Supplying the Initial state