Skip to content

Instantly share code, notes, and snippets.

@wwayne
Last active September 13, 2015 02:31
Show Gist options
  • Save wwayne/6a5d67a8c3e4d9892c88 to your computer and use it in GitHub Desktop.
Save wwayne/6a5d67a8c3e4d9892c88 to your computer and use it in GitHub Desktop.
import cssStyle from './style'
componentWillUnmount () {
// delete the style when the component unmount
let tag = document.querySelector('style[id="react-tooltip"]')
document.getElementsByTagName('head')[0].removeChild(tag)
}
render() {
// to check if the style has been existed
if (!document.getElementsByTagName('head')[0].querySelector('style[id="react-tooltip"]')) {
// insert the style into the head
let tag = document.createElement('style')
tag.id = 'react-tooltip'
tag.innerHTML = cssStyle
document.getElementsByTagName('head')[0].appendChild(tag)
}
return (...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment