{"id":18786828,"url":"https://github.com/chfoidl/react-html-converter","last_synced_at":"2025-12-23T11:30:16.810Z","repository":{"id":57329506,"uuid":"96449475","full_name":"chfoidl/react-html-converter","owner":"chfoidl","description":"Converts a raw HTML string into React Elements. Does convert components too.","archived":false,"fork":false,"pushed_at":"2018-03-22T23:02:41.000Z","size":149,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T16:51:33.318Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chfoidl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-06T16:16:44.000Z","updated_at":"2018-10-12T08:03:11.000Z","dependencies_parsed_at":"2022-09-14T19:01:39.388Z","dependency_job_id":null,"html_url":"https://github.com/chfoidl/react-html-converter","commit_stats":null,"previous_names":["sethorax/react-html-converter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Freact-html-converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Freact-html-converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Freact-html-converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoidl%2Freact-html-converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chfoidl","download_url":"https://codeload.github.com/chfoidl/react-html-converter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239706967,"owners_count":19683983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T20:52:40.700Z","updated_at":"2025-12-23T11:30:16.745Z","avatar_url":"https://github.com/chfoidl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-html-converter [![Build Status](https://travis-ci.org/Sethorax/react-html-converter.svg?branch=master)](https://travis-ci.org/Sethorax/react-html-converter) [![npm version](https://badge.fury.io/js/react-html-converter.svg)](https://badge.fury.io/js/react-html-converter)\n\nThis module converts a raw HTML string to a React element or an array of React elements. Component rendering is also supported.  \n\n\u003e Want to use this module with Preact? Checkout the Preact version - [preact-html-converter](https://github.com/Sethorax/preact-html-converter)\n\n## Installation\n\nInstall via **npm**:  \n`npm install --save react-html-converter`\n\nor **yarn**:  \n`yarn add react-html-converter`\n\n## General Info\n\nThis module ships with two integrations. One for node and one for the browser.  \nThe main reason behind having to versions is that altough the node version also works in the browser, the usage of `parse5` does add a lot to the overall bundle filesize. Therefore the browser version uses the native `DOMParser` instead of `parse5` to handle the html string parsing.\n\nModule usage is the same for node and for the browser.\n\nIf you use this module in node.js just import the node integration:  \n\n```js\nimport ReactHTMLConverter from 'react-html-converter/node'\n```\n\nIf you use it in the browser import the browser integration:  \n\n```js\nimport ReactHTMLConverter from 'react-html-converter/browser'\n```\n\n## Example\n\n```js\nimport React from 'react';\nimport ReactHTMLConverter from 'react-html-converter/node';\n\nclass Test extends React.Component {\n    render() (\n        return \u003cdiv\u003e{this.props.text}\u003c/div\u003e;\n    );\n}\n\nconst converter = new ReactHTMLConverter();\nconverter.registerComponent('test', Test);\n\nconst html = '\u003cdiv class=\"my-div\"\u003e\u003cTest text=\"Hello World\" /\u003e\u003c/div\u003e';\n\nclass App extends React.Component {\n    render() {\n        return (\n            \u003cdiv className=\"my-app\"\u003e\n                {converter.convert(html)}\n            \u003c/div\u003e\n        );\n    }\n}\n```\n\nAs shown in the above example the ReactHTMLConverter just takes a simple HTML string as an argument and returns a React element or an array of React elements. Those elements can then be easily used in other React components.\n\nThe ReactHTMLConverter is also able to create React components from the HTML string. To make this work all components must be registered in the converter before converting the HTML string. Just pass in the name of the component's tag and the component itself and the converter will convert those components if they appear in the HTML string.\n\nPlease note that any sibling nodes of a React component will not be rendered! Make sure to wrap the component with a div element.\n\n### Static rendering\nIf you just want to quickly render a html string, you can import the `convertStatic` function of this module. With this function only the root node will be converted to a React element. All child nodes will be rendered with `dangerouslySetInnerHTML`.\n\n## Disclosure\n\nThis module was heavily inspired by [react-render-html](https://github.com/noraesae/react-render-html).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchfoidl%2Freact-html-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchfoidl%2Freact-html-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchfoidl%2Freact-html-converter/lists"}