-
-
Save robertwbradford/3c856be2b6f3b38bd7d38fab33244f34 to your computer and use it in GitHub Desktop.
Simple React HTML comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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