react-sanitized

1.1.0 • Public • Published

react-sanitized

npm version npm downloads

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.

Package Sidebar

Install

npm i react-sanitized

Weekly Downloads

62

Version

1.1.0

License

MIT

Unpacked Size

9.64 kB

Total Files

5

Last publish

Collaborators

  • mionescu