1

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.

2
  • What did not work, do you have an example of what you tried, where did you get stuck? Commented Oct 13, 2021 at 14:29
  • npmjs.com/package/html-react-parser Commented Oct 13, 2021 at 14:30

2 Answers 2

4

You can try dangerouslySetInnerHTML https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome))It's work
3

You can do it with dangerouslySetInnerHTML property

const htmlString = `<h1>I'm a string with HTML!</h1>`;
const App = () => <div dangerouslySetInnerHTML={{ __html: htmlString }} />;

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.