0

I am making a call to an API, and the result has some HTML markup in it (example below). Is there a way I can use that markup when displaying the result, or am I better off just removing it? I am using React JS and rendering the result on to the webpage.

<p>Each night a park ranger will present an illustrated program highlighting a 
different aspect of Yellowstone’s wonders. Inquire at Fishing Bridge Visitor 
Information Center or look on local bulletin boards for the night's subject.</p> 
<p>Meet at the Bridge Bay Campground Amphitheater. <em>Dress warmly and bring a 
flashlight.</em> Accessible. 45 minutes.</p>
0

2 Answers 2

2

You can use below method, just pass html content and render returned value as usual.

export const renderHTMLContent = (htmlContent) =>
  React.createElement('div', {
    dangerouslySetInnerHTML: { __html: htmlContent},
  });
Sign up to request clarification or add additional context in comments.

Comments

0

Well if your HTML is Sanitized (You can used the sanitize-html package https://www.npmjs.com/package/sanitize-html, and will want to render the sanitized string using dangerouslySetInnerHTML https://reactjs.org/docs/dom-elements.html.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.