React Docgen is a library designed to extract information from React components, primarily for the purpose of generating documentation. It parses React component source code to identify prop types, default props, method definitions, and other relevant metadata, which can then be used by documentation tools or style guides. The current stable version is 8.0.3. The project maintains an active development pace, with frequent patch releases addressing bug fixes and minor improvements, while major versions primarily update Node.js compatibility. Its key differentiator is its direct association with the React ecosystem, offering robust AST parsing specifically tailored for React components, including support for various component definition patterns and TypeScript types.
npm install react-docgenVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `react-docgen` to parse a TypeScript React functional component, extracting its display name, description, and detailed prop information including types, descriptions, and default values.
Upgrade your Node.js environment to a compatible version (e.g., Node.js 20.9.0+ or 22.0.0+).
For advanced use cases, refer to the `react-docgen` documentation on GitHub for examples of creating and using `customResolvers` and `customHandlers` with `parseWithCustomResolvers`.
Always refer to the official GitHub repository (github.com/reactjs/react-docgen) for the most up-to-date documentation and examples, especially when encountering unexpected parsing behaviors.
Ensure that all props intended for documentation are statically defined in the component's source code, typically through TypeScript interfaces, JSDoc, or PropTypes.
Ensure `react-docgen` is installed (`npm install react-docgen` or `yarn add react-docgen`). For ESM projects, use `import { parse } from 'react-docgen';`. If using CommonJS, check your `tsconfig.json` or bundler settings for module resolution.Update `react-docgen` to version 8.0.1 or newer (`npm update react-docgen` or `yarn upgrade react-docgen`).
Verify that your component is defined and exported in a way `react-docgen` can understand (e.g., `export default function MyComponent`, `export const MyComponent = () => {}`). Consider using `parseWithCustomResolvers` and providing a custom resolver function if your component definition pattern is non-standard.No dependency data recorded yet.