简体   繁体   English

在 React.js 中的 JSX 中条件渲染十进制代码

[英]Conditional rendering decimal codes in JSX in React.js

I'm trying to render an ✕ and ✓ , conditionally with JSX, but this approach doesn't work.我正在尝试使用 JSX 有条件地渲染✕ 和 ✓ ,但这种方法不起作用。

<div>{exists ? &#10003; : &#10005;}</div>

What would be the right solution for achieving this?实现这一目标的正确解决方案是什么?

You have to wrap that using span and span should have an attribute of role="img" otherwise React will show warning.您必须使用span进行包装,并且 span 应该具有role="img"属性,否则 React 将显示警告。

<div>{true ? <span role="img">&#10003;</span> : <span role="img">&#10005;</span>}</div>

Please refer to the following code:请参考以下代码:

{exists ? <div>&#10005;</div> : <div>&#10003;</div>}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM