Reputation: 3467
I want that {'<'}
gets rendered as <
and not as <
.
let value1 = '<'
let value2 = '>'
return (<div>
{mycondition ? value1 : value2}
</div>
)
I've tried {<><</>}
and <>{<}</>
, but both didn't help.
Upvotes: 2
Views: 422
Reputation: 66
The problem is likely that it's interpreting the strings as actual text rather than HTML entities, so they're being escaped before rendering.
As per Mr.Gandhi's answer, you probably want to wrap them in a React fragment so that they are treated as actual HTML entities. Don't forget you can also store JSX values in variables, so your code could be reformatted to:
let value1 = <><</>;
let value2 = <>></>;
return (<div>
{mycondition ? value1 : value2}
</div>
);
Upvotes: 3
Reputation: 2466
Try this:
{<><</>} //<--- This will print <
{<>></>} //<--- This will print >
Upvotes: 1