-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
creating an XDM equivelent to the MDX playground #48
Comments
|
It's potentially going to live within a CMS so we can preview the content and save it. I tried import React, { useState } from 'react';
import * as runtime from 'react/jsx-runtime.js';
import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live';
import { evaluateSync } from 'xdm';
import './App.css';
function App(props) {
const [code, setCode] = useState('# Hello, world!\n\n This is some markup!');
return (
<div className="App">
<LiveProvider
code={code}
transformCode={(code) => {
let { default: Content } = evaluateSync(code, {
...runtime,
});
console.log(Content);
return String(Content);
}}
scope={{}}
>
<LiveEditor />
<LiveError />
<LivePreview />
</LiveProvider>
</div>
);
}
export default App; but now |
OK, getting closer. The next thing: the package The readme of |
Here’s a tiny, bad, example, of how it can be done: https://codesandbox.io/s/romantic-shannon-k1goq?file=/src/App.js. You could use |
Thanks for sending over the example, it made sense after looking at it that react-live isn't needed when it handles so much of it itself. I've managed to get something working with async here: https://github.com/Adam-Collier/vite-mdx-playground/tree/evaluate_async however there are a couple of problems I'm coming across when it comes to handling errors. For example if I was to do something like |
A bit of googling shows me: https://medium.com/trabe/catching-asynchronous-errors-in-react-using-error-boundaries-5e8a5fd7b971. |
Closing this for now. I think it has garnered enough conversation to be useful for future readers. Feel free to comment with more Qs tho! |
Hey, so I was looking to create an MDX playground and came across the one on the main MDXjs site (https://mdxjs.com/playground/) and I wondered if it would be possible to create one using XDM. So looking at https://github.com/mdx-js/mdx/blob/5169bf1f5d7b730b6f20a5eecee0b9ea0d977e56/packages/gatsby-theme-mdx/src/components/playground-editor.js and Chris Biscardi's post https://www.christopherbiscardi.com/post/using-mdxprovider-host-elements-in-react-live-scope I thought I'd give it a go. However, I think I may be misunderstanding how to use XDM in this instance because compileSync doesn't seem to output what the transformCode prop expects. Also, I was under the impression that we didn't need to use @mdx-js/react and the
MDXProvider
(which the MDX examples use) to render the content but this could be wrong?Here's some code:
Any help on this will be greatly appreciated and help me to understand how to use XDM more
The text was updated successfully, but these errors were encountered: