Skip to content

Instantly share code, notes, and snippets.

@tonytonyjan
Last active June 21, 2023 06:14
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tonytonyjan/616022dce75f8e6c1603bbeb94ec46a4 to your computer and use it in GitHub Desktop.
Save tonytonyjan/616022dce75f8e6c1603bbeb94ec46a4 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