rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.97k stars 867 forks source link

Store doesn't have a valid reducer while using persistCombineReducers #516

Closed therise3107 closed 7 years ago

therise3107 commented 7 years ago

This is related to v5. Error file image

Store.js

import { persistStore, persistCombineReducers } from 'redux-persist'
import { createStore } from 'redux'
import storage from 'redux-persist/es/storage'
import reducers from './reducers'

const config = {
  key: 'root',
  storage,
}

const reducer = persistCombineReducers(config, reducers)

const configureStore = () => {
  const store = createStore(reducer)
  const persistor = persistStore(store)

  return { store, persistor }
}

export default configureStore

redcuers/index.js

import { combineReducers } from 'redux'

const initialReducer = (state = [], action) => return state

const reducers = combineReducers({
  initialReducer 
})

export default reducers
rt2zz commented 7 years ago

perhaps the docs did not make this clear, but you should not need combineReducers that is handled by persistCombineReducers, so simply change reducers/index.js to be

import { combineReducers } from 'redux'

const initialReducer = (state = [], action) => return state

export default {
  initialReducer 
}

Open to suggestions for how to improve the docs around this.

therise3107 commented 7 years ago

Thank you @rt2zz. I'm closing this. Docs are fine just needs some more clarification on usage. I am just starting with redux-persist so I will gladly create PR's in coming days.

Coder108 commented 5 years ago

@rt2zz What if I want to clear all the stored data?