zce / velite

Turns Markdown / MDX, YAML, JSON, or others into app's data layer with Zod schema.
http://velite.js.org
MIT License
439 stars 20 forks source link

How to pass in props to the built mdx code? #101

Closed Adriel-M closed 5 months ago

Adriel-M commented 5 months ago

Hi, I'm coming from contentlayer and just wondering how you can pass props into the component inside the mdx file.

Previously I can just do https://github.com/Adriel-M/adriel.dev/pull/163/files#diff-06f49e3158547ee7b6e5ad074bcb5d474ecd3b8d7b1418c4ab1d89973e22c5edL19 and pass in the props in the mdx file via https://github.com/Adriel-M/adriel.dev/pull/163/files#diff-5cb1a6f54644fd51947374ebebad4a490a7d9cbc2d3d7a288619268911d3367cL31

Looking at the code, I see it's using mdx-js and I don't quite see a way to do this in the documentation: https://mdxjs.com/docs/using-mdx/#props. Am I missing something or is this just not possible with the mdx bundler of this project?

zce commented 5 months ago
# Hello {props.name.toUpperCase()}

The current year is {props.year}
export const MDXContent = ({ code, components }: MDXProps) => {
  const Component = useMDXComponent(code)
  return <Component components={{ ...sharedComponents, ...components }} name={'hello'} />
}
Adriel-M commented 5 months ago

That would do it. I just forgot to populate an environment variable. Thanks!