See demo
-
-
Save emerleite/e2a9ed5ee6efcf6320757352e6eaee49 to your computer and use it in GitHub Desktop.
Remote React Components Loading
This file contains 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
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