1
votes

I am getting the following error on my react-redux & redux-persist setup:

The above error occurred in the component: in Connect(App) (created by Route) in Route (created by withRouter(Connect(App))) in withRouter(Connect(App)) in Router (created by BrowserRouter) in BrowserRouter in PersistGate in Provider

I have it setup like this:

store.js

import {applyMiddleware, createStore} from 'redux';
import {persistStore,persistCombineReducers} from 'redux-persist';
import storage from 'redux-persist/es/storage' // default: localStorage if web, AsyncStorage if react-native

import { logger } from 'redux-logger';
import thunk from 'redux-thunk';
import promise from 'redux-promise-middleware';
import reducer from './reducers'

const middleware = applyMiddleware(promise(), thunk, logger);

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

const reducers = persistCombineReducers(config, {reducer});

export const configureStore = () => {
  const store = createStore(reducers, middleware);
  const persistor = persistStore(store);
  return { persistor, store };
};

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import {Provider} from 'react-redux';
import Bootstrap from 'bootstrap/dist/css/bootstrap.css';
import './css/app.css';
import App from './containers/App';

import { PersistGate } from 'redux-persist/es/integration/react'
import configureStore from './store';
const { persistor, store } = configureStore()


ReactDOM.render(
  <Provider store={store} >
    <PersistGate persistor={persistor}>
    <BrowserRouter>
      <App/>
    </BrowserRouter>
  </PersistGate>
  </Provider>,
  document.getElementById('root')
);

App.js

import React from 'react'
import { withRouter, Switch, Route } from 'react-router-dom'
import { connect } from 'react-redux'
...
@withRouter
@connect((store) => {
  return {
    isAuthenticated: store.auth.isAuthenticated,
  };
})
export default class App extends React.Component {
  render() {
...
  }
}

UPDATE 1

Full console log enter image description here

UPDATE 2

Is this the right way to declare the reducer? It works fine without redux-persist

authReducer.js

export default function reducer(state = {
  isAuthenticated: false
}, action) {
...
}

UPDATE 3

REHYDRATE console log enter image description here

UPDATE 4

index.js (in reducers folder)

import { combineReducers } from 'redux';
import user from './userReducer';
import auth from './authReducer';


export default combineReducers({
  user,
  auth
})
1
your app.js seems to be truncated or something..Daniel Khoroshko
I updated it, yet I think the issue is not in the missing code..galgo
Maybe it specifies more details on the error in the console? There should the second message I supposeDaniel Khoroshko
@DanielKhoroshko added the full loggalgo
It looks like the auth reducer is missing the initial state?Daniel Khoroshko

1 Answers

2
votes

So the problem was that one should not use both combineReducers and persistCombineReducers in one go. Similar situation could be found here https://github.com/rt2zz/redux-persist/issues/516