为什么没有redux-thunk的redux-observable无法正常工作?

时间:2019-10-06 12:42:56

标签: reactjs redux-observable

我完全遵循文档,并且总是得到

  

动作必须是普通对象

如果我将applyMiddleware放到epicMiddleware中,则一切正常

// src/store/index.js

import { createStore, combineReducers, applyMiddleware } from 'redux'
import { createEpicMiddleware, combineEpics } from 'redux-observable'
import thunk from 'redux-thunk'
import users from './users/reducer'
import countEpic from './users/epics'

const epicMiddleware = createEpicMiddleware()

const store = createStore(
  combineReducers({
    users,
  }),
  applyMiddleware(thunk, epicMiddleware)
)

epicMiddleware.run(combineEpics(countEpic))

export default store
// src/store/users/epics.js

import { mapTo } from 'rxjs/operators'
import { ofType } from 'redux-observable'

const countEpic = action$ =>
  action$.pipe(
    ofType('CLICK'),
    mapTo({ type: 'INCREMENT' })
  )

export default countEpic

0 个答案:

没有答案