Skip to content

Instantly share code, notes, and snippets.

@emerleite
Forked from tonytonyjan/1-README.md
Created October 9, 2018 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emerleite/e2a9ed5ee6efcf6320757352e6eaee49 to your computer and use it in GitHub Desktop.
Save emerleite/e2a9ed5ee6efcf6320757352e6eaee49 to your computer and use it in GitHub Desktop.
Remote React Components Loading
function loadRemoteComponent(url){
return fetch(url)
.then(res=>res.text())
.then(body=>{
var exports = {}
function require(name){
if(name == 'react') return React
else throw `You can't use modules other than "react" in remote component.`
}
eval(body)
return exports.__esModule ? exports.default : exports
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment