react-sanitized
v1.1.0
Published
A React component that will sanitize user-inputted HTML code, using the popular sanitize-html package
Downloads
76
Maintainers
Readme
react-sanitized
A React component that will sanitize user HTML code, using the popular sanitize-html package.
Install
This React component requires react as a peer dependency.
npm:
npm install react-sanitized --save
yarn:
yarn add react-sanitized
Example usage
import Sanitized from "react-sanitized";
const unsafeHtml =
"<a href=\"http://github.com\" onClick=\"'>alert('test')>Github</a>";
ReactDOM.render(
<Sanitized html={unsafeHtml} wrapperTag="label" />,
document.getElementById("reactRoot")
);It will output as:
<label>
<a href="http://github.com">Github</a>
</label>Options
You can add sanitize-html options as props. For example,
<SanitizedHTML
options={{
allowedTags: ["a"]
}}
html={'<a href="http://github.com">Github</a>'}
/>Contribution
Like us? Star us.
Found an issue? File us an issue.
