use antd design pro
<span
className={Style.opt}
style={{
color: canClickColor,
cursor: canClickCursor,
}}
onClick={() =>{this.unAssignSource(record, index)}}
>
</span>
unAssignSource = (record, index) => {
const { dispatch } = this.props;
const modal = confirm({
title: "",
content: "",
onOk: async () => {
await dispatch({
type: "assignSource/unAssignSource",
payload: {
index,
value: {
category_id: record.category_id,
resource_id: record.id,
},
},
});
modal.destroy();
}
})
}
Code of effects in model
*unAssignSource({ payload }, { call, put }) {
console.log("%cUN payload: ", "color: -sharpCC00FF; font-size: 18px;", payload)
const { index, value } = payload;
const response = yield call(unAssignSource, value);
if (response && response.code === 200) {
yield put({
type: "unAssignSource",
payload: index,
});
message.success("");
}
}
Code of reducers
unAssignSource(stats, { payload }) {
const newData = Array.from(stats.sourceList);
newData.splice(payload, 1);
return {
...stats,
sourceList: newData,
};
}
when I clicked to unbind, the unAssignSource effects was executed twice, and the second printed payload was 0
the second time it was called automatically. For some reason, ask God to solve