0

I am trying to configure an application and I am using: react class components, redux, react-redux, apollo-client, redux-persist and connected-react-redux and I am receiving the following error: "Uncaught TypeError: store.dispatch is not a function".
This is root reducer:

import { combineReducers } from "redux";
import { connectRouter } from "connected-react-router";

const createRootReducer = (history) => combineReducers({
    rooter: connectRouter(history),
    other reducers
})
export default createRootReducer

This is store.js:

import {createStore, applyMiddleware, compose} from 'redux'
import thunk from 'redux-thunk'
import createRootReducer from './Reducers'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import { createBrowserHistory } from 'history'
import { routerMiddleware } from 'connected-react-router'

const initialState = {}

export const history = createBrowserHistory()

const middware = [thunk]

const persistConfig = { 
    key: 'root',
    storage,     
}
const rootReducer = createRootReducer(history)


const persistedReducer = persistReducer(persistConfig, rootReducer)

const store = createStore(persistedReducer,
    initialState,
    compose(routerMiddleware(history),applyMiddleware(...middware))
    )

const  persistor = persistStore(store)    

export {store, persistor}

And this is index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import {
  ApolloClient,
  InMemoryCache,
  ApolloProvider,
} from "@apollo/client";
import { HashRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import  {store, persistor, history} from './store';
import { PersistGate } from 'redux-persist/integration/react'
import { ConnectedRouter } from 'connected-react-router';

export const client = new ApolloClient({
  uri: ' http://localhost:4000/',
  cache: new InMemoryCache()
});

ReactDOM.render(
  <React.StrictMode>

    <ApolloProvider client={client}>
       <Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
         
          <ConnectedRouter history={history}>
            <App />
          </ConnectedRouter>        
      
      </PersistGate></Provider >
    </ApolloProvider>

  </React.StrictMode>,
  document.getElementById('root')
);


React-router-dom version: 5.3.0. React-router version : 5.2.1
Could you please help me?

Prgrmist
  • 83
  • 1
  • 9
  • What, if any, debugging have you done already? Have you tried reducing your code to isolate where it breaks? – Drew Reese Jan 20 '22 at 22:07
  • @Drew Reese I did some debugging before reaching this point: when I was navigating the app, I was receiving, from the selector which is in my app, the next error: “Uncaught TypeError: Cannot destructure '_ref' as it is undefined. The above error occurred in the component:” from. I exported each component with “withRouter” and then I installed connected-react-router. I tried to reconfigure everything by following this instructions: [link](https://github.com/supasate/connected-react-router). And after this point I don't know anymore what to do. – Prgrmist Jan 20 '22 at 22:54

1 Answers1

1

The problem was with selector, because it is using some cache memory to memoize, and at first load, there was no cache memory. I found this post.
So I deleted the selector, and moved the function inside the reducer, for which was the selector.
Also I am not using "connected-react-router" anymore

Prgrmist
  • 83
  • 1
  • 9