这是我的index.js文件代码-
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import thunk from 'react-thunk';
import { createStore, applyMiddleware } from 'redux';
import Login from './Components/LoginRegister';
const store= createStore(
(state = {}) => state,
applyMiddleware(thunk)
);
ReactDOM.render((
<Provider store={store}>
<Router>
<switch>
<Route exact path="/" component={App} />
<Route path="/Loginregister" component={Login} />
</switch>
</Router>
</Provider> ),
document.getElementById('root')
);
当我在'applyMiddleware'中将'thunk'传递为'applyMiddleware(thunk)'时,我在控制台上遇到以下错误-
Uncaught TypeError: Cannot call a class as a function
at _classCallCheck (index.js:15)
at ReactThunk (index.js:36)
at applyMiddleware.js:51
at createStore (createStore.js:65)
at Object.<anonymous> (index.js:11)
at __webpack_require__ (bootstrap b42575b…:555)
at fn (bootstrap b42575b…:86)
at Object.<anonymous> (bootstrap b42575b…:578)
at __webpack_require__ (bootstrap b42575b…:555)
at bootstrap b42575b…:578
请让我知道我在做什么错。
您正在导入
import thunk from 'react-thunk';
但是thunk来自redux-thunk模块。
所以你应该导入
import thunk from 'redux-thunk';
此外,我认为您对“ createStore”的调用会出现问题。
createStore采用一个简化器(或组合的简化器)和可能的中间件。
减速器需要一个状态和一个动作,并且必须返回商店的新状态。
function reducer(state, action){
// Switch-Case for action.type
// Copy the current state and apply changes
return state;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句