Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Function value for defaultState #345

Open
dpikt opened this issue May 22, 2019 · 1 comment
Open

[Feature request] Function value for defaultState #345

dpikt opened this issue May 22, 2019 · 1 comment

Comments

@dpikt
Copy link

dpikt commented May 22, 2019

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
Copy link

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 )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants