-1

我正在尝试配置一个应用程序,我正在使用:react 类组件、redux、react-redux、apollo-client、redux-persist 和 connected-react-redux,我收到以下错误:“Uncaught TypeError: store.dispatch不是函数”。
这是根减速器:

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

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

这是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}

这是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 版本:5.3.0。React-router 版本:5.2.1
你能帮帮我吗?

4

1 回答 1

1

问题出在选择器上,因为它使用了一些缓存来记忆,并且在第一次加载时,没有缓存。我找到了这篇文章
所以我删除了选择器,并将函数移到了reducer中,它就是选择器。
我也不再使用“connected-react-router”了

于 2022-01-28T13:24:48.317 回答