remark-mdx-react-docgen-typescript is a Remark plugin designed to integrate `react-docgen-typescript` functionality directly into MDX documents. It allows developers to automatically extract and display TypeScript React component documentation within their MDX content using a directive syntax (e.g., `::component-docs{file="./Component.tsx"}`). The plugin processes MDX files, identifies these directives, and replaces them with JSX `<ComponentDocs>` elements containing `propsData` derived from the specified React component files. The current stable version is 1.0.1. Its release cadence appears to be ad-hoc, with recent updates in late 2023. Key differentiators include its tight integration with the `unified` and `remark` ecosystems, specifically for MDX, and its ability to leverage `react-docgen-typescript` for type-aware documentation generation, making it suitable for monorepos or design systems that use TypeScript and MDX for documentation.
npm install remark-mdx-react-docgen-typescriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `remark-mdx-react-docgen-typescript` with `@mdx-js/mdx` to process an MDX file containing a `::component-docs` directive. It shows the necessary imports for `remark-directive` and the docgen plugin, then compiles the MDX, illustrating how component documentation is extracted and inserted as JSX props into a `<ComponentDocs>` component.
Review the official `v1.0.0` release notes and usage examples to identify any renamed imports, options, or configurations and update your `unified`/`remark` plugin chain accordingly.
Ensure `remarkDirective` is listed in your `remarkPlugins` array *before* `remarkReactDocgen` when configuring `@mdx-js/mdx` or `unified`.
Set the `rootDir` option in the plugin configuration to your project's root path (e.g., `process.cwd()`) and use `<rootDir>/path/to/component.tsx` in your MDX directives for project-relative paths.
Provide a valid `tsConfigPath` within the `reactDocGenOptions` object, pointing to the `tsconfig.json` file relevant to your React components, or ensure your `tsconfig.json` is correctly configured for `react-docgen-typescript` to find it automatically.
Add `remarkDirective` to your `remarkPlugins` array before `remarkReactDocgen`: `remarkPlugins: [remarkDirective, remarkReactDocgen]`.
Verify the `file` path in your MDX directive is correct relative to the MDX file or correctly configured with `<rootDir>/` and the `rootDir` plugin option. Ensure the target file exports a valid React component.
Check your `reactDocGenOptions.tsConfigPath` to ensure it points to a valid `tsconfig.json`. Verify the `tsconfig.json` includes the component files and has appropriate compiler options (e.g., `jsx`). Ensure the TypeScript component file is valid and compilable.