我正在尝试将Redux集成到reactjs.I在开发工具中发现以下错误消息。我知道这究竟是什么,我们如何解决它?
Uncaught (in promise) Error: Actions must be plain objects. Use custom middleware for async actions.
at dispatch (createStore.js:158)
at eval (middleware.js:22)
at eval (middleware.js:67)
at Object.eval [as callApi] (bindActionCreators.js:5)
at HomePage.componentDidMount (eval at ./app/containers/HomePage/index.js (0.chunk.js:154), <anonymous>:101:28)
at HomePage.proxiedComponentDidMount (eval at ./node_modules/react-proxy/modules/createPrototypeProxy.js (0.chunk.js:943), <anonymous>:61:40)
at eval (ReactCompositeComponent.js:265)
at measureLifeCyclePerf (ReactCompositeComponent.js:75)
at eval (ReactCompositeComponent.js:264)
at CallbackQueue.notifyAll (CallbackQueue.js:76)
答案 0 :(得分:0)
我认为您在调度函数中传递了一个函数,默认情况下不支持该函数。如果你想做这样的事情,你应该使用thunk中间件。
import {createStore, compose, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import rootReducer from '../reducers';
function configureStoreProd(initialState) {
const middlewares = [
// Add other middleware on this line...
// thunk middleware can also accept an extra argument to be passed to each thunk action
// https://github.com/gaearon/redux-thunk#injecting-a-custom-argument
thunk,
];
return createStore(rootReducer, initialState, compose(
applyMiddleware(...middlewares)
)
);
}