【发布时间】:2018-12-23 04:11:50
【问题描述】:
我在使用 redux-thunk 时遇到以下错误。我被困了好几天,我在堆栈溢出中找到了很多关于这个问题的答案,但没有一个有帮助。抱歉,这可能是一个愚蠢的问题。任何帮助将不胜感激。非常感谢
我面临的错误: 未捕获的错误:操作必须是普通对象。使用自定义中间件进行异步操作。
Store.js:
import { createStore, applyMiddleware } from 'redux'
import ReduxThunk from 'redux-thunk'
import reducer from './reducers'
const store = createStore(reducer, {}, applyMiddleware(ReduxThunk))
export default store
我的行动:
export const getAllClientList = () => async (dispatch) => {
try {
let clientList = await axios.get(API_URL)
dispatch({ type: types.RECEIVE_CLIENTLIST, clientList })
} catch (e) {
dispatch({ type: types.ERROR, message: e.message })
}
}
【问题讨论】:
标签: reactjs redux async-await react-redux redux-thunk