javascript - 在 react-redux 中运行两次的动作
问题描述
我正在使用 React 构建一个待办事项应用程序。在从 Firestore DB 请求/响应之后,我正在向减速器发送一个动作(COMPLETED_TASK)。由于我也在使用 redux-logger,因此我注意到此操作运行了两次。
这是动作的代码:
export const completedTask = (data, completedBool) => async (
dispatch,
getState
) => {
try {
const formObj = cloneDeep(data);
const onlyDate = formObj.taskTime;
const getId = formObj._id;
const getDate = cleanDate(onlyDate, 'DD');
const getMonth = cleanDate(onlyDate, 'MM');
const getYear = cleanDate(onlyDate, 'YYYY');
const { uid } = getState().firebase.auth;
const todoUpdateString = `todoListByDate.${getDate}.${getId}.completed`;
await db.doc(`todos-col/${uid}&${getMonth}${getYear}`).update({
[todoUpdateString]: completedBool,
});
formObj.completed = completedBool;
dispatch({
type: todoTypes.COMPLETED_TASK,
payload: {
todosByMonthData: {
[`${getMonth}-${getYear}`]: {
[getDate]: { [getId]: formObj },
},
},
selectedDate: {
selectedDay: getDate,
selectedMonth: getMonth,
selectedYear: getYear,
},
},
});
} catch (err) {
console.log('Error!!', err);
}
};
在屏幕截图中,在 1 处,动作被分派给减速器(它记录来自下面减速器的有效负载数据),然后再次调度类型为:“COMPLETED_TASK”的动作,但减速器没有接收到它。
为什么会这样?有人可以帮忙吗?
解决方案
推荐阅读
- ubuntu - 在 Ubuntu Xenial (Ubuntu 16.04) 上安装 RabbitMQ 的简单方法
- javascript - 在特定时间段内查找两个值之间的值
- excel - Excel VBA - 将一块文本分成可用的部分
- angular - 是否可以进行深度 ng-content 选择?
- jquery-animate - 滚动网页时如何从左到右或从右到左动画div框
- angular6 - Account 类型的参数不能分配给参数类型 any[] angular 6
- c# - C# 将 XML 汇率解析为 ECB 的字典
- php - 评论和子评论形式:在while循环(php)中显示和隐藏它并基于jquery脚本逻辑时出现问题
- android - Android Studio 找不到基本名称消息的捆绑包。AndroidJpsBundle,语言环境 en_US
- python - 经过一些迭代后,ANN 变得神经质