react-redux <Provider> - 空白页



我的程序运行得很好,直到我开始使用"react redux"。现在我在localhost上得到一个空白页面,控制台显示错误:

未捕获的类型错误:发现不可调用的@@iterator

这是我的代码:

存储

import {createStore, applyMiddleware, compose} from 'redux'
import thunk from 'redux-thunk';
import rootReducer from './reducers/rootReducer';

import {sessionService} from 'redux-react-session';

const initialState = {};
const middlewares = {thunk};

const store = createStore(rootReducer, initialState, compose (applyMiddleware(...middlewares)));

sessionService.initSessionService(store);

export default store

rootReducer

import {combineReducers} from 'redux';

//session
import {sessionReducer } from "redux-react-session";

const rootReducer = combineReducers ({
session: sessionReducer
});

export default rootReducer;

应用

import React from 'react';

// Pages
import Home from './pages/Home';
import Login from './pages/Login';
import Signup from './pages/Signup';
import Dashboard from './pages/Dashboard';


//Styled Components
import {StyledContainer} from './components/Styles';

import { HashRouter as Router, Route, Routes } from "react-router-dom";

function App() {
return (
<Router>
<StyledContainer>
<Routes>
<Route path='/signup' element={<Signup/>} />

<Route path='/login' element={<Login/>} />

<Route path='/dashboard' element={<Dashboard/>} />

<Route path='/' element={<Home/>} />

</Routes>
</StyledContainer>
</Router>
);
}

export default App;

索引

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';


// auth
import {Provider } from 'react-redux';
import store from "./auth/store";

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

我不知道出了什么问题,也没有经验。我试着遵循一个教程:https://www.youtube.com/watch?v=HCnHYz6TXA4
提前感谢!

看起来像是reactjs存储中Found不可调用@@迭代器的重复

您正试图将排列运算符应用于商店设置中的对象。普通的javascript对象是不可迭代的,这就是为什么您会收到关于不可调用的@@迭代器的错误。


const middlewares = {thunk};

const store = createStore(rootReducer, initialState, compose (applyMiddleware(...middlewares)));

middlewares应该是一个数组:


const middlewares = [thunk];

const store = createStore(rootReducer, initialState, compose (applyMiddleware(...middlewares)));

相关内容

  • 没有找到相关文章

最新更新