I'm creating a simple React application, and I have to map through an array like this:
const data = [
{
id: 1,
string: "my dog is a <strong>poodle</strong>"
},
{id: 2,
string: "my cat is nice"
}
]
Sometimes inside the string, I have some strong tags to render. When I try to render that sentence, I will see the html rendered. If I try to use a template literal and assign that strong tag to a variable, I will have the [object object] error. How can I render tags in this situations? Trying if possible to avoid the "setDangerouslyHTML" prop. This is my mapping function:
data.map(da=>{
return (<li key={da.id}>{da.string}/>)
}
Thanks for the help!