In my electron application, I want to offer some kind of extensibility for the UI. The users should be able to create a react component inside of a text editor inside of my application. Their code gets saved to a file. They also can define where the component should be placed inside my UI.
The problem is: I can't seem to figure out how to parse and inject the user-defined JSX in my existing react app.
I thought I try with babel transformSync, but I can't get it working. This is what I have so far:
const DynamicComponent = (props) => {
const reactCode = `
return (
<div>
<h1 >Hello, World!</h1>
</div>
)
`;
const transpiledCode = transform(reactCode, {
presets: ["@babel/preset-react"]
}).code;
console.log("transpiled", transpiledCode);
globalThis["React"] = React;
const Dynamic = new Function(`return ${transpiledCode}`)();
return <Dynamic />;
};
https://codesandbox.io/s/mobx-state-tree-todolist-3umd4?file=/components/TodoList.js
I'd like to have the "<h1>Hello, World!</h1>" rendered below my todo list.