Basicaly you want to show html given from another source (usually as text)
dangerouslySetInnerHTML
is under the DOM elements in react as an attribute and is React's replacement for innerHTML
known from vanilla JavaScript
when using dangerouslySetInnerHTML
attribute you need to send an object with an __html
key like so:
<div dangerouslySetInnerHTML={{ __html: 'beware of dangerously Set InnerHTML' }}>
watch out of this attribute, its not called this way for no reason, unvigilent usage can open you up for cross-site scripting attack (XSS attack)
further explanation thanks to @FrancisJohn in this thread:
the scenes when you use dangerouslySetInnerHTML it lets React know
that the HTML inside of that component is not something it cares
about.
Because React uses a virtual DOM, when it goes to compare the diff
against the actual DOM, it can straight up bypass checking the
children of that node because it knows the HTML is coming from another
source. So there's performance gains.