英文:
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"
}
答案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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论