Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Replace the MDX Content Wrapper with an MDXProvider in Gatsby MDX


    MDX content has a root element called wrapper. This element is a React.Fragment by default which can lead to some warnings if you pass props to the MDX component generated from a file, like gatsby-mdx's src/pages support does. Here's how to fix that.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: Here, we have some MDX, a running Gatsby project, and the result of that MDX displayed on the page. Note that we have an MDX provider wrapping our entire application with no components being passed in currently.

    When using an MDX file in source pages in a Gatsby project, you may see this invalid prop warning in the console. This is because the default wrapping element for MDX content is a fragment and Gatsby will pass in any page context to the page component.

    In this case, since we're using an MDX file as a page, that means the MDX file will get any page context passed in as a prop, and react.fragment cannot take any props. To rectify this, we can replace wrapper with a fragment, but not passing in any of the extra props.

    Note that when our application refreshes, we no longer see the fragment error because we are no longer passing in the props to the fragment.