What are the different ways of initializing a react redux store's initial global state? I see two ways this redux could set an initial global state
Let's say we have a single reducer and all the javascript is in one file.
function rootReducer(state = "Initial Reducer State!", action){
switch(action.type) {
case SET_TEXT:
return "Ignore this case statement it won't run"
default:
return state;
}
}
(1) I know you can use something like createStore(rootReducer, initialState)
.
const store = createStore(
rootReducer,
initialState
)
const initialState = {
text: "Initial Global State!"
}
(2) However, I noticed some repos setting an initialState
to a blank object, but the redux store shows a global state has been populated. Example from this stackoverflow post: how to set initial state in redux
const store = createStore(
combineReducers({
text: rootReducer
}),
initialState
)
const initialState ={}
Resulting global store:
(1) outputs {text: "Initial Global State!"}
(2) outputs {text: "Initial Reducer State!"}
Why does #2 work the way it does?
When and where does it get set?