I'm trying to write a code-editor using react-live.
The following works, where I hardcode the sample code into a string:
const code="<div>hello</div";
...
<LiveProvider code={code}>
<LiveEditor />
<LiveError />
<LivePreview />
</LiveProvider>
But, for more advanced usages (when there is more than a trivial amount of example code), it is not efficient to write code inside a string. So, my underlying question is how can we effectively write example code which populates a code-editor?
Ideally, we could write the sample code in a separate module, as actual code, and then somehow read it in when setting up the code-editor component. However, this doesn't work:
import sampleCode from "./sampleCode.jsx";
const code = sampleCode.toString(); // '[object Object]'
Additionally, defining the sample code right there within the file doesn't work:
const code = <div>hi</div>;
code.toString(); // '[object Object]'
How can I convert actual code snippets into a string representation?