You can use action-async- script -loader as a higher order component for this: https://github.com/leozdgao/react-async-script-loader
Just install it via npm:
npm install
, javascripts cdn, scriptLoader, URL-, .
import scriptLoader from 'react-async-script-loader';
// Your component code:
class YourComponent extends React.Component {
render() {
return <p>{
this.props.isScriptLoadSucceed ? 'Scripts loaded.' : 'Loading...'
}</p>;
}
}
export default scriptLoader([
'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js'
])(YourComponent);
, , . ( ).
Decorator (ES7) , , HOC, README.