Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
react-html-string
Advanced tools
Readme
A React declarative component for converting HTML strings into React components. Avoids the use of dangerouslySetInnerHTML and converts standard HTML elements, attributes and inline styles into their React equivalents or Custom Components
.
$ npm install react-html-string
or
$ yarn add react-html-string
import HTMLString from 'react-html-string';
const html = `
<div>
<h1>
Hello from
<a
href="https://github.com/MomenSherif/react-html-string"
target="_blank"
>React HTML String</a
>
</h1>
<hr />
<ul>
<li>Render HTML string safely</li>
<li>Provide <b>Custom Components</b> if needed</li>
</ul>
<p>Don't forget to ⭐️ the project</p>
</div>
`;
export default function App() {
return (
<div>
<h1>Hello, React!</h1>
<HTMLString html={html} />
</div>
);
}
import HTMLString from 'react-html-string';
import Heading from './components/Heading';
const components = {
a: props => <a {...props} style={{ color: 'red' }} />,
h1: Heading,
};
const html = `
<div>
<h1>
Hello from
<a
href="https://github.com/MomenSherif/react-html-string"
target="_blank"
>React HTML String</a
>
</h1>
<hr />
<ul>
<li>Render HTML string safely</li>
<li>Provide <b>Custom Components</b> if needed</li>
</ul>
<p>Don't forget to ⭐️ the project</p>
</div>
`;
export default function App() {
return (
<div>
<h1>Hello, React!</h1>
<HTMLString html={html} components={components} />
</div>
);
}
Each component is strongly typed with the equivalent dom node type.
import HTMLString, { Components } from 'react-html-string';
import Heading from './components/Heading';
const components: Components = {
a: props => <a {...props} style={{ color: 'red' }} />,
h1: Heading,
};
const html = `
<div>
<h1>
Hello from
<a
href="https://github.com/MomenSherif/react-html-string"
target="_blank"
>React HTML String</a
>
</h1>
<hr />
<ul>
<li>Render HTML string safely</li>
<li>Provide <b>Custom Components</b> if needed</li>
</ul>
<p>Don't forget to ⭐️ the project</p>
</div>
`;
export default function App() {
return (
<div>
<h1>Hello, React!</h1>
<HTMLString html={html} components={components} />
</div>
);
}
FAQs
A React declarative component for converting HTML strings into React components. Avoids the use of dangerouslySetInnerHTML and converts standard HTML elements, attributes and inline styles into their React equivalents or `Custom Components`.
The npm package react-html-string receives a total of 487 weekly downloads. As such, react-html-string popularity was classified as not popular.
We found that react-html-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.