我有下面的代码用于在react-redux中组合存储和reducer。
由于react和react-redux版本的缘故,它在我以前的应用程序中运行良好。
TypeError:中间件不是函数
代码:
import 'rxjs'
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { reducer as formReducer } from 'redux-form'
import thunk from 'redux-thunk'
import promise from 'redux-promise-middleware'
import { createEpicMiddleware, combineEpics } from 'redux-observable'
// import { createLogger } from 'redux-logger'
import user, { userEpic } from './user/duck'
import userApp, { userAppEpic } from './user-app/duck'
import app from './app'
// Bundling Epics
const rootEpic = combineEpics(
userEpic,
userAppEpic
)
// Creating Bundled Epic
const epicMiddleware = createEpicMiddleware()
// Define Middleware
const middleware = [
thunk,
promise(),
epicMiddleware
]
// Define Reducers
const reducers = combineReducers({
app,
user,
userApp,
form: formReducer
})
// Create Store
export default createStore(reducers,
applyMiddleware(...middleware))
epicMiddleware.run(rootEpic)
有人可以帮我解决问题吗?
答案 0 :(得分:2)
按照Doc:
... middleware(参数):符合Redux的功能 中间件API。每个中间件都接收Store的调度和getState 用作命名参数,并返回一个函数。
这意味着我们需要将函数传递给applyMiddleware
。在您的情况下,您传递的是promise()
而不是promise
(函数),这就是为什么它因错误而失败:
中间件不是功能
这样写:
const middleware = [ thunk, promise, epicMiddleware ];