How can I convert an HTML object containing a span element within a string into something that Reactjs can actually render as HTML?
To clarify, here's what I have:
let myObject = "apple tree"
I wrote a function that wraps the word apple in a span tag (html object)
<span style="color: red;">apple</span>tree
my website is displaying:
[object Object] tree
BUT it should be displaying
apple tree
where "apple" is colored red because it is wrapped in a span
I'm passing the string into my component like this:
return (<div>{myObject}</div>)
Not sure how to render this object as actual HTML element, and not sure if I doing dangerouslySetInnerHTML is the best and only option here too