-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Variable definition in MDX broken when referenced in Playground #1247
Comments
Hey, I added an empty line between the mdx and js lines and the code worked as expected. Can you check : https://github.com/rakannimer/docz-issue-1247 ? |
@rakannimer Thanks for creating that test case! I updated the above example accordingly. |
I wanted to use a variable to control state at my <Playground>
{
() => {
const App = () => {
const [open, setOpen] = React.useState(false)
return (
<>
<Button onClick={() => setOpen(true)}>Notify</Button>
<Snackbar
open={open}
onClose={() => setOpen(false)}
message="My variable works!"
/>
</>
)
}
return <App />
}
}
</Playground> Con of this approach is that the function is going to appear at the |
Hey all ! Thanks @thiagozf for your workaround, but as you said it doesn't allow to share code between playgrounds. The problem wasn't with mdx parsing, the exports work as expected if you use them in JSX outside of the Playground component. For example : export const myVariable = 'Yay!'
# Hello, world!
<div>{myVariable}</div> would work as expected. But a different scope is provided inside the playground that didn't have access to exports in the mdx file. I added all mdx exports to the Playground scope which should fix your use-case. It will be released with the next docz version, meanwhile you can try it out with :
You can also check out this repo for an example of using named exports and named function exports in playground that are defined in the mdx file : https://github.com/rakannimer/docz-use-mdx-exports-in-playground Example mdx : Hello
export const myVariable = "Yay!";
export function b() {
return "Hello";
}
# Hello, world!
<h2>{myVariable}</h2>
import { Playground } from "docz";
<Playground>
<div>
{myVariable}
{b()}
</div>
</Playground>
That should solve things for your use case right ? Cheers ! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bug Report
The MDX docs state one should be able to declare variables within the MDX document through
export
like so:To Reproduce
Expected behavior
It should render
<div>Yay!</div>
and variablemyVariable
should be available inPlayground
The text was updated successfully, but these errors were encountered: