0

I am making a query from an api, the api returns a result snippet like this:

"<span class="searchmatch">Justin</span> Drew <span class="searchmatch">Bieber</span> (/ˈbiːbər/; born March 1, 1994) is a Canadian singer and songwriter. After a talent manager discovered him through his YouTube videos"

when i render it in my component like this:

{this.props.snippet} 

it returns a text, but I want to render it as an html element. help?

gpbaculio
  • 5,693
  • 13
  • 60
  • 102

1 Answers1

-2

You are most likely looking for dangerouslySetInnerHTML

And render it like this:

<div dangerouslySetInnerHTML={{__html: yourStringFromApi}} />

Note though that this can be quite dangerous and should be avoided if possible.

Amid
  • 21,508
  • 5
  • 57
  • 54