hasura / gatsby-gitbook-starter

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

Can't import React component #19

Closed lusa closed 4 years ago

lusa commented 4 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 4 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 4 years ago

That worked, thanks!