0

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

Peter
  • 63
  • 1
  • 4
  • Why dont you simply concat the file as string to your code? Or import userCode from "user/"; where user simply returns the user uploaded file – Jonas Wilms Jul 28 '17 at 09:29
  • The users code is in a database. I think one solution is, that every request with /user/ will get the transformed script from the database. But isn't there another way to import something from memory instead of from a resource at serverside? – Peter Jul 28 '17 at 09:41

0 Answers0