reactjs - 将 Promise 传递给 reducer 并在那里解决它是一件坏事吗?
问题描述
我正在做我的爱好项目,它是用 React、Redux 和 Redux-thunk 制作的。
我现在有 3 个减速器:
- 攻击者
- 后卫
- 组合
在我的动作创建器中,我必须按特定顺序调度多个动作。我需要将某种数据从第二个动作传递给第三个动作。所以我这样做了:
Actions.js
export const deleteAttacker = id => {
return (dispatch) => {
dispatch({
type: DELETE_ATTACKER,
payload: {
id
}
});
updateDefenders(id, dispatch)
.then(data => dispatch({
type: COMBINATIONS_DELETE_ATTACKER,
payload: {
id,
data,
}
}));
};
};
export const updateDefenders = (id, dispatch) => {
return new Promise((resolve) => {
dispatch({
type: UPDATE_DEFENDERS,
payload: {
id,
resolve
}
});
});
}
Reducers/Defenders.js
...
case UPDATE_DEFENDERS: {
const data = [];
...
// push new elements into the 'data' array
// update the newState object
action.payload.resolve({ data });
// Return the data array, so I can pass that array to the third action.
// Is it a bad thing to do...?
return {
...newState
};
}
...
我的问题:可以在我的 reducer 中调用 resolve 方法吗?或者这是一件坏事,我应该以不同的方式解决我的问题?
感谢您的建议!
解决方案
推荐阅读
- python - 我正在使用 openpyxl 在模板中加载数据,当我打开时我在目标文件中收到警告
- swift - ios - tvOS - UICollectionViewCompositionalLayout 引脚选择 ROW 到 TOP
- python - PipEnv 的 Pipfile 部分
- magento-2.3 - 我想覆盖一个模型(Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector)
- python - 如何安装python应用程序+visualstudio编译器?
- reactjs - React 查询突变现在确实会使用相同的输入再次触发
- kubernetes - 现有 Helm Chart 的 k8s helm-push 目标
- php - 用于 woocommerce 的基于角色的价格插件
- image - windows 随机图像层生成器
- python - 是否可以在 Python 脚本中将变量传递给 MDX 查询?