npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-jsx-html-comments

v1.0.1

Published

Enable HTML comments and conditional IE comments in React components and JSX using a Web Component (W3C Custom Element).

Downloads

39

Readme

NPM npm version

React / JSX HTML Comments

Enable HTML comments and conditional IE comments in React components and JSX using a Web Component.

This 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.

The solution use the native Custom Elements V1 API so it does NOT depends on document.registerElement that requires a polyfill for most browsers, e.g. WebReflection/document-register-element.

You can read more about Web Components at www.webcomponents.org, facebook.github.io/react/docs/webcomponents.html and developer.mozilla.org.

Include the following javascript in your application to enable the <react-comment> Web Component.

/**
 * <react-comment> Web Component
 *
 * @usage
 *  <react-comment>Comment-text, e.g. [if lte IE 9]><script ... /><![endif]</react-comment>

 * @result
 *  <!--Comment-text, e.g. [if lte IE 9]><script ... /><![endif]-->
 */

class ReactComment extends window.HTMLElement {
  get name () {
    return 'React HTML Comment'
  }

  connectedCallback () {
    /**
    * Firefox fix, is="null" prevents attachedCallback
    * @link https://github.com/WebReflection/document-register-element/issues/22
    */
    this.is = ''
    this.removeAttribute('is')
    this.outerHTML = '<!--' + this.textContent + '-->'
  }
}

window.customElements.define('react-comment', ReactComment)

To include a comment in your JSX or React component, simply include the <react-comment> 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.

Install

NPM

Use 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.

npm install --save react-jsx-html-comments

Vanilla JavaScript

Download the index.js file (rename if you want) and save it in your proyect.

Import

NPM

If 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.

import 'react-jsx-html-comments' // ES2015
// or
require('react-jsx-html-comments') // CommonJS
// or
define(['react-jsx-html-comments'], function() {}) // AMD

Vanilla JavaScript

If 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:

<script src="/path/to/index.js"></script>

Use

JSX

<footer>Copyright {year}, Website.com</footer>
<react-comment>Page loaded in {loadtime} seconds</react-comment>

React component / element

var MyComponent = React.createClass({
 render: function() {
  return React.createElement('react-comment',{},'This is sample comment text.');
 }
});

This solution is a migration of the code from optimalisatie to the new Custom Elements API V1 that does NOT require polyfill, you can see the original code here.