【发布时间】:2022-09-15 05:31:47
【问题描述】:
如果有评论的条件,我会更新状态?.length,我只想在有评论的情况下更新评论,一切正常,但我有一个问题。 我可以更轻松地完成这种情况吗?我的意思是没有映射2次。
const changeStatus = (id, status,comment) => {
axios
.post(\"http://localhost:5000/changeStatus\", {
id: id,
status: status,
comment: comment,
})
.then((res) => {
comment?.length
? setStatus(
status.map((val) => {
return val.id == id
? {
...val,
status: status,
comment: comment
}
: val;
})
) : setStatus(
status.map((val) => {
return val.id == id
? {
...val,
status: status,
}
: val;
})
);
标签: reactjs dictionary axios