See demo
Last active
June 21, 2023 06:14
-
-
Save tonytonyjan/616022dce75f8e6c1603bbeb94ec46a4 to your computer and use it in GitHub Desktop.
Remote React Components Loading
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
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