我有這樣的消息時,我嘗試用派遣一個Redux的承諾,我闖到大明白我錯了ReactJS +終極版+紅眼-的thunk不能派遣承諾
Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
1)這裏我createStore
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import createLogger from 'redux-logger'
import RootReducer from '../reducers/root.reducer'
export default function configureStore(preloadedState) {
const store = createStore(
RootReducer,
preloadedState,
compose(
applyMiddleware(thunk), createLogger()
)
)
return store
}
2)在我的組分i分派這樣
dispatch(myAction(myParam))
3)這裏我的動作是myAction代碼
export function myAction(dispatch, myParam){
return fetchList(myParam)
.then(response => response.json())
.then(json => {
console.log(json)
})
.catch(err => {
if (err)
throw err
})
}
但是,如果我把我的動作像這樣,它的工作:
myAction(dispatch, myParam)
我覺得這是終極版,形實轉換問題,但爲什麼...