Skip to content

Instantly share code, notes, and snippets.

@itsMapleLeaf
Created January 27, 2018 17:43
Show Gist options
  • Save itsMapleLeaf/ab1a2943053d55f49a9e776d9da4709a to your computer and use it in GitHub Desktop.
Save itsMapleLeaf/ab1a2943053d55f49a9e776d9da4709a to your computer and use it in GitHub Desktop.
import React from 'react'
class ScriptLoader extends React.Component {
state = {
loaded: false
}
componentDidMount() {
const script = document.createElement('script')
script.src = 'http://example.script/src'
script.onload = () => {
this.setState({ loaded: true })
}
document.head.appendChild(script)
}
render() {
if (!this.state.loaded) {
return null
}
return <SomeComponent />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment