Skip to content

Instantly share code, notes, and snippets.

@robertwbradford
Forked from alexeychikk/ReactComment.jsx
Last active August 30, 2018 21:09
Show Gist options
  • Save robertwbradford/3c856be2b6f3b38bd7d38fab33244f34 to your computer and use it in GitHub Desktop.
Save robertwbradford/3c856be2b6f3b38bd7d38fab33244f34 to your computer and use it in GitHub Desktop.
Simple React HTML comment
/*
This is a stripped down fork of https://gist.github.com/alexeychikk/bfe72a072a9a962f2da900b6151e4aae
<HTMLComment text="This will be displayed in an HTML comment" />
*/
import React, { Component } from "react";
import ReactDOM from "react-dom";
export default class HTMLComment extends Component {
componentDidMount() {
const el = ReactDOM.findDOMNode(this);
ReactDOM.unmountComponentAtNode(el);
el.outerHTML = this.createComment();
}
createComment() {
const { text = "" } = this.props;
return `<!-- ${text} -->`;
}
render() {
return <div />;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment