{"id":14990434,"url":"https://github.com/rodrigotomees/react-jsx-html-comments","last_synced_at":"2025-03-22T00:25:51.591Z","repository":{"id":57333563,"uuid":"246259494","full_name":"RodrigoTomeES/react-jsx-html-comments","owner":"RodrigoTomeES","description":"Enable HTML comments and conditional IE comments in React components and JSX using a Web Component (W3C Custom Element).","archived":false,"fork":false,"pushed_at":"2020-03-12T10:18:54.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T13:09:08.098Z","etag":null,"topics":["customelement","html","html-comments","javascript","jsx","npm","npm-package","react","web-components","webcomponent","webcomponents"],"latest_commit_sha":null,"homepage":"","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/RodrigoTomeES.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":"2020-03-10T09:32:12.000Z","updated_at":"2022-02-11T15:44:59.000Z","dependencies_parsed_at":"2022-08-24T20:51:01.092Z","dependency_job_id":null,"html_url":"https://github.com/RodrigoTomeES/react-jsx-html-comments","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Freact-jsx-html-comments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Freact-jsx-html-comments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Freact-jsx-html-comments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Freact-jsx-html-comments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RodrigoTomeES","download_url":"https://codeload.github.com/RodrigoTomeES/react-jsx-html-comments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244888406,"owners_count":20526792,"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":["customelement","html","html-comments","javascript","jsx","npm","npm-package","react","web-components","webcomponent","webcomponents"],"created_at":"2024-09-24T14:20:08.331Z","updated_at":"2025-03-22T00:25:51.574Z","avatar_url":"https://github.com/RodrigoTomeES.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM](https://img.shields.io/npm/l/react-jsx-html-comments?style=flat)](https://github.com/RodrigoTomeES/react-jsx-html-comments/blob/master/LICENSE)\n[![npm version](https://badge.fury.io/js/react-jsx-html-comments.svg)](https://badge.fury.io/js/react-jsx-html-comments)\n\n# React / JSX HTML Comments\nEnable HTML comments and conditional IE comments in React components and JSX using a [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components).\n\nThis repository is intended to share a solution to include native HTML comments in React components and JSX. It uses a Web Component (W3C Custom Element) to transform text to a native HTML comment.\n\nThe solution use the native Custom Elements V1 API so it does **NOT** depends on [document.registerElement](https://developer.mozilla.org/en-US/docs/Web/API/Document/registerElement) that requires a polyfill for most browsers, e.g. [WebReflection/document-register-element](https://github.com/WebReflection/document-register-element).\n\nYou can read more about Web Components at [www.webcomponents.org](http://webcomponents.org/), [facebook.github.io/react/docs/webcomponents.html](https://facebook.github.io/react/docs/webcomponents.html) and [developer.mozilla.org](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements).\n\nInclude the following javascript in your application to enable the `\u003creact-comment\u003e` Web Component. \n\n```javascript\n/**\n * \u003creact-comment\u003e Web Component\n *\n * @usage\n *  \u003creact-comment\u003eComment-text, e.g. [if lte IE 9]\u003e\u003cscript ... /\u003e\u003c![endif]\u003c/react-comment\u003e\n\n * @result\n *  \u003c!--Comment-text, e.g. [if lte IE 9]\u003e\u003cscript ... /\u003e\u003c![endif]--\u003e\n */\n\nclass ReactComment extends window.HTMLElement {\n  get name () {\n    return 'React HTML Comment'\n  }\n\n  connectedCallback () {\n    /**\n    * Firefox fix, is=\"null\" prevents attachedCallback\n    * @link https://github.com/WebReflection/document-register-element/issues/22\n    */\n    this.is = ''\n    this.removeAttribute('is')\n    this.outerHTML = '\u003c!--' + this.textContent + '--\u003e'\n  }\n}\n\nwindow.customElements.define('react-comment', ReactComment)\n```\n\nTo include a comment in your JSX or React component, simply include the `\u003creact-comment\u003e` tag with the comment-text as content and import index.js (you can rename the file) or use the npm package [react-jsx-html-comments](https://www.npmjs.com/package/react-jsx-html-comments).\n\n### Install\n#### NPM\nUse the following command in your directory to use and save the npm package. This will put index.js inside `node_modules/react-jsx-html-comments/` of your project.\n```\nnpm install --save react-jsx-html-comments\n```\n\n#### Vanilla JavaScript\nDownload the index.js file (rename if you want) and save it in your proyect.\n\n### Import\n#### NPM\nIf you're working with a tool like Browserify, Webpack, RequireJS, etc, you can import the script at some point before you need to use the API.\n\n```javascript\nimport 'react-jsx-html-comments' // ES2015\n// or\nrequire('react-jsx-html-comments') // CommonJS\n// or\ndefine(['react-jsx-html-comments'], function() {}) // AMD\n```\n\n#### Vanilla JavaScript\nIf you're not using a module system, just place index.js (rename if you want) somewhere where it will be served by your server, then put:\n```html\n\u003cscript src=\"/path/to/index.js\"\u003e\u003c/script\u003e\n```\n\n### Use\n#### JSX\n```jsx\n\u003cfooter\u003eCopyright {year}, Website.com\u003c/footer\u003e\n\u003creact-comment\u003ePage loaded in {loadtime} seconds\u003c/react-comment\u003e\n```\n\n#### React component / element\n```javascript\nvar MyComponent = React.createClass({\n render: function() {\n  return React.createElement('react-comment',{},'This is sample comment text.');\n }\n});\n```\n\nThis solution is a migration of the code from [optimalisatie](https://github.com/optimalisatie) to the new Custom Elements API V1 that does **NOT** require polyfill, you can see the original code [here](https://github.com/optimalisatie/react-jsx-html-comments).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigotomees%2Freact-jsx-html-comments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigotomees%2Freact-jsx-html-comments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigotomees%2Freact-jsx-html-comments/lists"}