0

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 ?

2 Answers 2

1

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

...
return (
  ...
  <div dangerouslySetInnerHTML={{ __html: data.content }} />
  ...
)
...
Sign up to request clarification or add additional context in comments.

1 Comment

This solves the issue but the developer should be aware of cross-site scripting (XSS) attacks and therefore only use this in case the source of the data is trusted like something managed by app administrators.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.