c8r / x0

Document & develop React components without breaking a sweat

Home Page:https://compositor.io/x0/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

_app.js: render function or Component, and MDX access to props

avaragado opened this issue · comments

In the README, the Custom App section talks about using the render function to pass props to child routes.

In the equivalent page in the nicely formatted doc there's no mention of using this render function. It mentions using Component instead.

Which approach should we be using?

And also, the reason I went down this hole: I can use _app.js to pass props to child routes. I can access these props in JS files: they're provided to the React component exported from the file.

How do I access these props in MDX files?

To expand on the second question. Consider this _app.js:

// _app.js

import React from 'react';

const App = props => {
    const { render } = props;

    return (
        <React.Fragment>
            {render({ foobar: 12345 })
        </React.Fragment>
    );
};

export default App;

And now this MDX file under the doc root:

import { Box } from 'rebass';

How do I access `foobar` here?

Either render or Component should work, but Component is probably a simpler, more React-like approach. As for props to MDX components, that isn’t supported yet – was a feature in early MDX that got removed along the way, but I think it’s coming back