我可以对这些操作使用批处理吗?
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,
});
}
};
我希望我的组件重新渲染一次,但动作 B 在动作 A 之后等待并运行 所以我可以用它来代替 Promise.all();
batch(async () => {
await dispatch(getAAction());
await dispatch(getBAction());
});