【发布时间】:2020-04-21 02:41:46
【问题描述】:
我正在尝试创建一个预订应用程序。我对 React 很陌生,我尝试搜索,但似乎找不到问题所在。 由于我的代码有 400 多行,我将只发布我遇到错误的那些。 我在关注这篇文章https://medium.com/@kris101/building-appointment-scheduler-app-in-react-and-nodejs-d01f7294a9fd
具体错误有:
第 136:11 行:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions 第 139:11 行:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions 第 147:7 行:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions
我尝试禁用 eslint,但是当我这样做时,我遇到了更多错误。
handleDBReponse(response) {
const reservations = response;
const today = moment().startOf("day"); //start of today 12 am
const initialSchedule = {};
initialSchedule[today.format("YYYY-DD-MM")] = true;
const schedule = !reservations.length
? initialSchedule
: reservations.reduce((currentSchedule, reservation) => {
const { slot_date, slot_time } = reservation;
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
});
}
【问题讨论】:
-
在哪一行导致错误?
-
136 !currentSchedule[slot_date] 139 Array.isArray(currentSchedule[dateString]) 147 slot.length
-
你能把错误截图加到帖子里吗?
-
我更新了帖子:)
标签: reactjs