【问题标题】:expected an assignment or function call and instead saw an expression react期望一个赋值或函数调用,而是看到一个表达式反应
【发布时间】:2019-05-11 13:16:54
【问题描述】:

我搞错了 在那些线上 (127 / 130 / 138) 我不知道代码到底有什么问题,但我想这是语法错误或类似的东西? 任何帮助 相同的代码在 react-script 1.1.0 中运行良好 ps 我正在使用 react-script 3.0.0

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] //line 127
            ? (currentSchedule[dateString] = Array(8).fill(false)) 
            : null;
          Array.isArray(currentSchedule[dateString]) //line130

            ? (currentSchedule[dateString][slot_time] = true)
            : null;
          return currentSchedule;
        }
        , initialSchedule);

    for (let day in schedule) {
      let slots = schedule[day];  //138
      slots.length
        ? slots.every(slot => slot === true)
          ? (schedule[day] = true)
          : null
        : null;
    }

【问题讨论】:

  • 可能这是 linting 错误,而不是编译错误。
  • @VikashSingh 那我该怎么办?
  • 只需禁用 linting 或提高代码质量。
  • @VikashSingh 还是同样的问题:/

标签: javascript node.js reactjs


【解决方案1】:

我们以以下为例:

currentSchedule[slot_date] ?
  (currentSchedule[dateString] = Array(8).fill(false)) 
  : null;

lint 期待类似:

currentSchedule[dateString] = currentSchedule[slot_date] ?
  (Array(8).fill(false)) 
  : null;

【讨论】:

    猜你喜欢
    • 2020-06-17
    • 2018-01-16
    • 2020-12-28
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 2020-02-12
    相关资源
    最近更新 更多