错误:预期是一个赋值或函数调用,而看到的是一个表达式 no-unused-expressions

huangapple go评论87阅读模式
英文:

error : Expected an assignment or function call and instead saw an expression no-unused-expressions

问题

在我的React错误中,出现了一个期望赋值或函数调用,而实际上看到的是一个表达式no-unused-expressions。

const handleIndexScore = () => { 
    setScore(score >= 80) ? "A" : (score >= 70) ? "B" : (score >= 60) ? "C" : (score >= 50) ? "D" : "E";
}

查看图像描述

英文:

in my react error Expected an assignment or function call and instead saw an expression no-unused-expressions

const handleIndexScore = () => { 
    setScore (score >= 80) ? "A" : (score >= 70) ? "B" : (score >= 60) ? "C" : (score >= 50) ? "D" : "E"
  }

enter image description here

答案1

得分: 1

你原本想要这样做:

setScore (score >= 80 ? "A" : (score >= 70) ? "B" : (score >= 60) ? "C" : (score >= 50) ? "D" : "E")

而你现在基本上是这样做的:

let x = setScore (score >= 80)
x ? "A" : (score >= 70) ? "B" : (score >= 60) ? "C" : (score >= 50) ? "D" : "E"
英文:

You wanted to do:

setScore (score >= 80 ? "A" : (score >= 70) ? "B" : (score >= 60) ? "C" : (score >= 50) ? "D" : "E")

What you basically do now is:

let x = setScore (score >= 80)
x ? "A" : (score >= 70) ? "B" : (score >= 60) ? "C" : (score >= 50) ? "D" : "E"

huangapple
  • 本文由 发表于 2023年5月25日 00:12:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76325529.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定