Aniket Yadav
Aniket Yadav

Reputation: 61

How to render HTML Template as response from json in react js

My api response is

{
"content" : "<div><p>Some random text</p></div>"
}

I am passing the html template as value in json response content. In my application then I am trying to render the content but the output is

My output : <div><p>Some random text</p></div>

Actual output should be : Some random text

Can anyone guide what I am missing out ?

Upvotes: 0

Views: 427

Answers (2)

Pranay Binju
Pranay Binju

Reputation: 621

You can also checkout dangerouslySetInnerHTML to set innerHTML for HTML you get as string in response.

...
return (
  ...
  <div dangerouslySetInnerHTML={{ __html: data.content }} />
  ...
)
...

Upvotes: 1

Deep1man3
Deep1man3

Reputation: 192

In order to converts raw HTML to a React DOM structure you need a library: html-to-react

Upvotes: 0

Related Questions