Created
January 27, 2018 17:43
-
-
Save itsMapleLeaf/ab1a2943053d55f49a9e776d9da4709a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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