Is there a way to insert HTML as a string into the MongoDB and then get it in react app and put it in component as html? I've tested DomParser in js but It did not work.
CodePudding user response:
You can try dangerouslySetInnerHTML
https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml
CodePudding user response:
You can do it with dangerouslySetInnerHTML
property
const htmlString = `<h1>I'm a string with HTML!</h1>`;
const App = () => <div dangerouslySetInnerHTML={{ __html: htmlString }} />;