【发布时间】:2019-03-06 07:27:00
【问题描述】:
我是 reactjs 新手,正在尝试将 redux 与我现有的项目集成。
这是我在商店中的 index.js 文件
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 user, { userEpic } from './user/duck'
import app from './app'
// Bundling Epics
const rootEpic = combineEpics(
userEpic
)
// Creating Bundled Epic
const epicMiddleware = createEpicMiddleware(rootEpic)
// Define Middleware
const middleware = [
thunk,
promise(),
epicMiddleware
]
// Define Reducers
const reducers = combineReducers({
app,
user,
form: formReducer
})
// Create Store
export default createStore(reducers,window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), applyMiddleware(...middleware))
这里是duck.js
const createUserEpic = (action$) =>
action$
.ofType(SIGNUP_CONCIERGE)
.mergeMap((action) => {
return Rx.Observable.fromPromise(api.signUpConcierge(action.payload))
.flatMap((payload) => ([{
type: SIGNUP_CONCIERGE_SUCCESS,
payload
}]))
.catch((error) => Rx.Observable.of({
type: SIGNUP_CONCIERGE_ERROR,
payload: { error }
}))
})
export const userEpic = combineEpics(
createUserEpic
)
这给我带来了错误TypeError: action$.ofType(...).mergeMap is not a function
自从我更新 react、react-redux、redux-observable 版本后,我一直收到此错误。
我在这里做错了什么?请帮忙!!!
【问题讨论】:
标签: reactjs react-redux redux-thunk redux-observable