I would like to allow a user of a webapp to upload some code-fragments in React (with JSX) that should be embedded dynamically in the code.
For instance the user writes a class with a render-Method that returns
<div>hello {this.props.name}</div>
Then the System should transpile this by Babel and maybe transform the result into something secure by Google Caja. After that I want to be able to embed this in a way like that:
let code = theUsersCodeFragment;
import ForeignClass from code;
render() {
return <MyContainer>
<ForeignClass name={"John"}>
</MyContainer>
}
Is this possible (I know dynamic imports are just in stage 3)? I just found a way to load modules from memory by require: Load node.js module from string in memory