React |
I had this problem - I needed to add an HTML string in a React application, coming from a WYSIWYG editor, but simply adding {myString} to the JSX was escaping the HTML.. so the HTML tags were displayed to the user!
Solution: use dangerouslySetInnerHTML
You can use the dangerouslySetInnerHTML attribute on an HTML element to add an HTML string inside its content:
<div dangerouslySetInnerHTML={{ __html: props.house.description }}></div>
Remember that it’s called dangerously for a reason. HTML is not escaped at all in this case, and it might cause XSS issues.
No comments:
Post a Comment