[Feature request] Function value for defaultState
dpikt opened this issue · 1 comments
dpikt commented
There are times when I reinitialize my store (by setting state = undefined
) and I want the defaultValue
to be computed again. A function value for defaultState
could enable this:
function getDefaultState () {
return { thing: localStorage.getItem('thing') }
}
const reducer = handleActions({}, getDefaultState)
Thoughts?
simondell commented
Redux already provides a mechanism for passing an initial store state into the root reducer. Can you use that?
import { createStore } from 'redux'
import rootReducer from './my/reducers/root'
// ...
if( isHappening ) {
store = undefined
const initialState = getDefaultState()
store = createStore( rootReducer, initialState )
}