今天在使用redux-thunk踩坑,报错
Actions must be plain objects. Use custom middleware for async actions
搜解决方法,说我没有正确使用redux-thunk。
我在创建store的时候,使用的是
const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose(
applyMiddleware(thunk)
))
我之前这样写,没有报错,但是这次使用dispatch方法返回一个函数就报错了。
应该改为:
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducer, composeEnhancers(
applyMiddleware(thunk)
))