A little helper for simpler dangerouslySetInnerHTML
npm install react-inner-htmlA little helper for simpler dangerouslySetInnerHTML using the spread operator.
Before:
`` After: function MyComponent() { Or, if you get your html component through a prop, which was the case for me, it gets even simpler: function MyComponent({ content }) { Remember: So, use it carefully. npm: yarn:jsx
function MyComponent() {
return hot html' }} />;
}
``jsx
import html from 'react-inner-html';
return hot html')} />;
}
``jsx`
import html from 'react-inner-html';
return
}``
Setting HTML from code is risky because it's easy to inadvertently expose your users to a cross-site scripting (XSS) attack.`Installation:
bash`
npm i -S react-inner-html`bash``
yarn add react-inner-html