gpt4 book ai didi

reactjs - 错误: Expected an assignment or function call and instead saw an expression no-unused-expressions. How to solve it?

转载 作者:行者123 更新时间:2023-12-02 10:55:58 29 4
gpt4 key购买 nike

我实际上正在尝试将我的数据库连接到React应用,并且它会在三个不同的地方(向我显示以下“>>”突出显示此错误)

 handleDBReponse(response) {
const appointments = response;
const today = moment().startOf("day"); //start of today 12 am
const initialSchedule = {};
initialSchedule[today.format("YYYY-DD-MM")] = true;
const schedule = !appointments.length
? initialSchedule
: appointments.reduce((currentSchedule, appointment) => {
const { slot_date, slot_time } = appointment;
const dateString = moment(slot_date, "YYYY-DD-MM").format(
"YYYY-DD-MM"
);
>> !currentSchedule[slot_date]
? (currentSchedule[dateString] = Array(8).fill(false))
: null;
>> Array.isArray(currentSchedule[dateString])
? (currentSchedule[dateString][slot_time] = true)
: null;
return currentSchedule;
}, initialSchedule);
for (let day in schedule) {
let slots = schedule[day];
>> slots.length
? slots.every(slot => slot === true) ? (schedule[day] = true) : null
: null;
}
this.setState({
schedule: schedule
});
}

最佳答案

在这三种情况下,您都在做类似

condition ? something = somethingElse : null
因此,如果condition虚假,它将求值为 false null,这实际上没有任何意义。我认为,如果您执行以下操作,则更容易阅读和摆脱警告
if (condition) something = somethingElse
所以在第一种情况下
!currentSchedule[slot_date]
? (currentSchedule[dateString] = Array(8).fill(false))
: null;
应该
if (!currentSchedule[slot_date]) {
(currentSchedule[dateString] = Array(8).fill(false));
}

关于reactjs - 错误: Expected an assignment or function call and instead saw an expression no-unused-expressions. How to solve it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64031502/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com