React-redux-starter-kit: How to reset entirely the redux state?

Created on 2 Jun 2016  路  4Comments  路  Source: davezuko/react-redux-starter-kit

Hi, I really love this react-redux starter kit, thanks for the great work.

I have implemented a simple authentication flow and I'm trying to reset the whole redux state at the user logout, but I'm not able.

I've take inspiration by this snippet on SO:

const appReducer = combineReducers({
  /* your app鈥檚 top-level reducers */
})

const rootReducer = (state, action) => {
  if (action.type === 'USER_LOGOUT') {
    state = undefined
  }

  return appReducer(state, action)
}

but I don't understand how/where I can apply the solution above at the starter-kit.

In these past days i've already tried without success to enhance the makeRootReducer function with a _high order reducer_ for resetting the state, but It doesn't seem the right solution.

Does anyone have some hints to point me in the right direction? Thanks!

Most helpful comment

I don't think the problem is related to this repo but you can try this. (not tested)

export const makeRootReducer =
  (asyncReducers) =>
  (state, action) =>
  combineReducers({
    // reducers...
    router,
    ...asyncReducers
  })(action.type === 'STATE_RESET' ? undefined : state, action)

All 4 comments

I don't think the problem is related to this repo but you can try this. (not tested)

export const makeRootReducer =
  (asyncReducers) =>
  (state, action) =>
  combineReducers({
    // reducers...
    router,
    ...asyncReducers
  })(action.type === 'STATE_RESET' ? undefined : state, action)

Thanks a lot @kolpav ! It works, I tried with very similar approaches in these past days but without success.

This just made my day 馃嵒 !

It works! Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ciokan picture ciokan  路  4Comments

postalservice14 picture postalservice14  路  4Comments

glifchits picture glifchits  路  3Comments

jokeyrhyme picture jokeyrhyme  路  5Comments

zeroc picture zeroc  路  4Comments