doczjs / docz

✍ It has never been so easy to document your things!
https://docz.site
MIT License
23.6k stars 1.46k forks source link

How to share repetitive code for multiple playgrounds? #1613

Open vimkin opened 3 years ago

vimkin commented 3 years ago

Question

How to share repetitive code for multiple playgrounds?

Description

For instance, how can we leverage DRY code and make const value = 0; readable in all the showcases? It's going to have the same value for each showcase. One possible solution: I could have created a separate file, where I put all the repetitive code, but my question implies if there are ways to do it in the same mdx file?

Code sample:

## Showcase 1
<Playground>
    {() => {
        const value = 0;
        return value;
    }}
</Playground>

## Showcase 2
<Playground>
    {() => {
        const value = 0;
        return value;
    }}
</Playground>