我正在构建一个带有反应的网页。我使用了 udemy 的教程,作者使用 redux promise 进行休息调用。它在课程中起作用。
在我自己的项目中,我设置了相同的所有内容,当我尝试使用 redux-promise 中间件创建商店时,在启动网站时出现以下错误:
Uncaught TypeError: middleware is not a function
at http://localhost:3000/index.js:34412:16
at Array.map (native)
at http://localhost:3000/index.js:34411:27
at Object.<anonymous> (http://localhost:3000/index.js:15744:70)
at Object.<anonymous> (http://localhost:3000/index.js:15748:27)
at Object.options.path (http://localhost:3000/index.js:15749:30)
at __webpack_require__ (http://localhost:3000/index.js:658:30)
at fn (http://localhost:3000/index.js:86:20)
at Object.<anonymous> (http://localhost:3000/index.js:35118:18)
at __webpack_require__ (http://localhost:3000/index.js:658:30)
错误出现在这里(根据控制台):
applyMiddleware.js:39
如果我使用另一个中间件,比如 redux-thunk,它就可以工作(好吧,除了我的休息调用,但那是另一回事了)。有什么建议为什么会发生此错误?
我正在运行的版本:
"axios": "^0.15.3",
"es6-promise": "^4.0.5",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^5.0.4",
"react-router": "^3.0.2",
"redux": "^3.6.0",
"redux-promise": "^0.5.3"
我的 index.tsx:
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import {Router, Route, browserHistory, IndexRoute} from 'react-router';
import thunk from 'redux-thunk';
import reduxPromise from 'redux-promise';
import reducers from './app/reducers';
import routes from './routes';
import './index.scss';
const createStoreWithMiddleware = applyMiddleware(reduxPromise)(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<Router history={browserHistory} routes={routes} />
</Provider>
,document.getElementById('root')
);
您是否需要更多信息(如减速器、操作等)?
调用此行时出现错误:
<Provider store={createStoreWithMiddleware(reducers)}>