Render HTML as React element, possibly replacing dangerouslySetInnerHTML
npm install react-render-htmlRender HTML as React element, possibly replacing dangerouslySetInnerHTML
It renders a provided HTML string into a React element.
``js
import renderHTML from 'react-render-html';
renderHTML("GitHub")
// => React Element
// GitHub
`
It may be used in the render method in a React component:
`js`
let App = React.createClass({
render() {
return (
{renderHTML(someHTML)}
);
}
});
Or just by itself
`js`
ReactDOM.render(renderHTML(someHTML), document.getElementById('app'));
If a provided HTML contains several top-level nodes, the function will return
an array of React elements.
`js`
renderHTML('
// => [React Element
- Can make use of React's reconciliation for plain HTML too
- Fully compatible with JSX
- It uses parse5 to parse HTML, which can
result in large bundle size
- Can result in slower rendering speed, mainly for parsing
Install with NPM:
``
npm i --save react-render-html
Import with CommonJS or whatever:
`js
const renderHTML = require('react-render-html');
import renderHTML from 'react-render-html';
``
When a bug is found, please report them in Issues.
Also, any form of contribution(especially a PR) will absolutely be welcomed :beers: