[英]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 ? ✓ : ✕}</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">✓</span> : <span role="img">✕</span>}</div>
Please refer to the following code:请参考以下代码:
{exists ? <div>✕</div> : <div>✓</div>}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.