Reputation: 459
I want to know how to store an html tag as a Javascript object. Consider the following code:
const temp = () => {
const complexity = "O(n<sup>2</sup>)"
return (
<div>
{complexity}
</div>
)
}
Right now, it renders as the exact string: O(n<sup>2</sup>)
Instead I want the <sup>
to be treated as a the html tag and render as: O(n2)
Any help is appreciated. Thanks
Upvotes: 0
Views: 1089
Reputation: 69
I would recommend you to wrap them with empty fragments instead. E.g.
const complexity = <>O(n<sup>2</sup>)</>
Upvotes: 0
Reputation: 61
This is not working because its not HTML its jsx.
jsx must retun a single element..so just wrap your <sup>
tag inside any other tag
const Test = () => {
const complexity = <span>O(n<sup>2</sup>)</span>
return (
<div>
{complexity}
</div>
)
}
Upvotes: 1
Reputation: 943561
Don't use a string in the first place, use JSX:
const complexity = <React.Fragment>O(n<sup>2</sup>)</React.Fragment>
The React.Fragment is only needed here because you have three top-level nodes (text, element, text).
Upvotes: 2