背景
Redux store仅支持同步数据流。使用thunk
等中间件可以帮助在Redux应用中实现异步性,可以将thunk
看做store的dispatch()
方法的封装器;我们可以使用thunk
action creator派遣函数或Promise,而不是返回action对象。
注意,没有thunk的话,默认是同步派遣;
示例:向后台发送请求
不使用redux-thunk
// store/actionCreator.js
export const getAllItemAction = (todos)=>({
type:constants.GET_ALL_ITEM_ACTION,
todos
});
// app.js
async