Bryan Enid
Bryan Enid

Reputation: 484

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.

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

What would be the right solution for achieving this?

Upvotes: 1

Views: 137

Answers (2)

Erick
Erick

Reputation: 1146

Please refer to the following code:

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

Upvotes: 0

Himanshu Singh
Himanshu Singh

Reputation: 1953

You have to wrap that using span and span should have an attribute of role="img" otherwise React will show warning.

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

Upvotes: 2

Related Questions