Uncaught Error: Actions must be plain objects. Use custom middleware for async actions. |
1 2 3 4 5 | import { createStore, applyMiddleware } from 'redux' import { reducers } from './reducers' import thunk from 'redux-thunk' export const store = createStore(reducers, applyMiddleware(thunk)) |
1 2 3 4 5 | import { createStore, applyMiddleware } from 'redux' import { reducers } from './reducers' import { thunk } from './middleware' export const store = createStore(reducers, applyMiddleware(thunk)) |
1 2 3 4 5 6 7 8 9 10 11 12 | export function thunk(store) { return function(dispatch) { return function(action) { if(typeof action === 'function') { action(dispatch, store.getState) // invoke the action } else { return dispatch(action) // dispatch normally } } } } |
1 2 3 4 5 6 7 8 | export const thunk = store => dispatch => action => { if(typeof action === 'function') { action(dispatch, store.getState) // invoke the action } else { return dispatch(action) // dispatch normally } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |