简体   繁体   English

三元运算符:“解析错误:预期的属性分配”

[英]Ternary Operator: “Parsing error: Property assignment expected”

This is my code basically:这基本上是我的代码:

const [jwtToken, setJwtToken] = useState("")
return(
    {(jwtToken === "") ? <div>Yes</div> : <div>No</div>}
)

Why do I get this error?:为什么会出现此错误?:

在此处输入图像描述

I remember it worked like this for me (added some parentheses and empty html tag):我记得它对我来说是这样的(添加了一些括号和空的 html 标签):

return(
  <>{(jwtToken === "") ? (<div>Yes</div>) : (<div>No</div>)}</>
)
  const [jwtToken, setJwtToken] = useState("")
  return (
    (jwtToken === "") ? <div>Yes</div> : <div>No</div>
  )

In this case you don't need to use {}在这种情况下,您不需要使用 {}

You can also use React.Fragment你也可以使用 React.Fragment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 三元运算符:需要赋值或函数调用,而看到的是表达式 - Ternary operator: Expected an assignment or function call and instead saw an expression Typescript 可选链结合三元运算符解析错误 - Typescript optional chaining combined with ternary operator parsing error Button 中的三元运算符导致“...”预期的 TS(1005) 错误 - Ternary Operator in Button causes '…' expected TS(1005) error 反应三元运算符错误 - React ternary operator error 通过三元运算符映射数组分配失败? - Mapped array assignment through ternary operator fails? 三元运算符 ? 在 Javascript 中从预期向后解析 - Ternary operator ? in Javascript is resolving backwards from expected 三元运算符没有按预期工作 - Ternary operator doesn't work as expected 反应:如果使用三元运算符在 Api 中没有图像,则显示消息。 获取解析错误:意外的令牌 - React: show message if no image in Api using ternary operator. Getting parsing error: unexpected token 如果可选道具是 TypeScript 中的数组,如何在三元运算符中使用 boolean 赋值 - How to use boolean assignment in ternary operator if optional prop is an array in TypeScript 期望赋值或函数调用,而是看到了三元表达式 - Expected an assignment or function call and instead saw an expression on ternary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM