1.1.0 • Published 5 years ago

react-sanitized v1.1.0

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

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.

1.1.0

5 years ago

1.0.0

5 years ago