Skip to content

How to import MDX components in .tsx files? #512

Description

@wuchendi

I am using contentlayer and MDX, and I am testing based on the example template shadcn/next-contentlayer.

However, I have encountered an issue and I'm not sure how to correctly import MDX components in .tsx files.

code:
image

Activity

  1. schardev commented on Jul 16, 2023

    @schardev

    You cannot just import .mdx files and expect them to work as component. You have to give the raw code to useMDXComponent() hook you get from next-contentlayer/hooks which will in turn give you a component that you can render. See this and this.

  2. wuchendi commented on Jul 16, 2023

    @wuchendi
    Author

    You cannot just import .mdx files and expect them to work as component. You have to give the raw code to useMDXComponent() hook you get from next-contentlayer/hooks which will in turn give you a component that you can render. See this and this.

    Thank you for your reply. Is that right?
    image

  3. schardev commented on Jul 16, 2023

    @schardev

    @wuchendi I will suggest you to go through the official contentlayer docs. Start with this page if you have already set up most stuff.

  4. locked and limited conversation to collaborators on Jul 17, 2023
  5. converted this issue into a discussion #514 on Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions