javascript - 使用一批 react-redux 调度多个异步操作
问题描述
我可以对这些操作使用批处理吗?
import { batch } from 'react-redux';
export const getAAction = () => async (dispatch) => {
const response = await getAService();
if (response.ok) {
dispatch({
type: constants.GET_A,
payload: response?.data,
});
}
};
export const getBAction = () => async (dispatch) => {
const response = await getBService();
if (response.ok) {
dispatch({
type: constants.GET_B,
payload: response?.data,
});
}
};
我希望我的组件一旦重新渲染,但 Action B 在 Action A 之后等待并运行,所以我可以使用它来代替 Promise.all();
batch(async () => {
await dispatch(getAAction());
await dispatch(getBAction());
});
解决方案
推荐阅读
- strapi - Strapi 关系的 POST 详细信息
- .net - Azure 服务总线 - 更新锁无法正常工作
- javascript - 如何在 ReactJS 中渲染嵌套数据?
- sql-server - Active Directory 组的 SqlTableDependency 权限问题
- css - 如何修复顶部导航栏粘滞位置?
- .net-core - Raspberry Pi 4 上 Visual Studio 2019 CE 的 Dotnetcore 3.0 远程调试 - 权限不足
- ruby-on-rails - 如何在 rake 任务中读取 csv 文件
- excel - VBA:如何知道图表是否在单独的工作表中?
- python - 使用 brew (homebrew) 在 Mac 上安装后,python 无法导入图形工具
- python - 为什么我遇到 kivy 设计师的“kivy.adapters”问题?