hasura / gatsby-gitbook-starter

Generate GitBook style modern docs/tutorial websites using Gatsby + MDX
https://hasura.io/learn/graphql/react/introduction/
MIT License
985 stars 376 forks source link

Can't import React component #19

Closed lusa closed 5 years ago

lusa commented 5 years ago

How can we import React components into mdx files? I tried a very simple example and it didn't work:

---
title: "Button"
metaTitle: "Button Example"
metaDescription: "This is the meta description for this page"
---

import {Button} from './button'

Example of a button.

<Button/>
10chars commented 5 years ago

@lusa I had the same problem. You need to import in the src/components/mdxComponents/index.jsfile which is past to the MDXProvider's components prop in src/components/layout.js

src/components/mdxComponents/index.js:

import MyComponent from './MyComponent';
export default {
  /* other components */
  MyComponent
};

inside your mdx content:

<MyComponent />
lusa commented 5 years ago

That worked, thanks!