reactjs - 在自定义 Redux 中间件中等待
问题描述
我将如何在自定义中间件中使用 await。
const customMiddleware= (store) => (next) => (action) => {
if(action.type === 'Start'){
const apiResult = await FetchFromApi;
}
const result = next(action);
return result;
}
解决方案
在操作之前使用异步
const customMiddleware= (store) => (next) => async (action) => {
if(action.type === 'Start'){
const apiResult = await FetchFromApi;
}
const result = next(action);
return result;
}