npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@iviva/react-tsdoc

v0.2.7

Published

Tool to generate documentation and type definitions for your React component library

Readme

React TypeScript Document Generator

React TypeScript Document Generator is a command-line tool that helps you automatically generate clear, well-structured documentation and type definitions for your React components, hooks, and utility functions written in TypeScript.

It scans your code, reads TSDoc-style comments, and produces:

  • Markdown documentation with prop tables, examples, and type signatures.
  • Type definition files (.d.ts) for easy API sharing.

Whether you’re building a reusable UI library or maintaining an internal component set, this tool saves you from writing documentation manually and keeps it consistent with your code.


Why Use This Tool?

  • Stay in sync: Documentation is generated directly from your source code.
  • Easy to maintain: Update your comments, re-run the tool, and everything stays current.
  • Supports multiple React patterns: Functional components, class components, hooks, and more.
  • Clear output: Easy-to-read Markdown for documentation sites and type definitions for developers.

Installation

Install globally via npm:

npm install -g react-tsdoc

How It Works

  1. You write code with TSDoc comments describing your components, props, hooks, or functions.
  2. Run the CLI commands to generate documentation and type definitions.
  3. Share or publish the generated docs and .d.ts files.

Commands & Parameters

The CLI provides two main commands:

1. Generate Type Definitions

react-tsdoc types <path-to-root-ts> <output.d.ts> --module-name <module-name>

Purpose: Creates a .d.ts type definition file for your public API.

Parameters:

  • <path-to-root-ts> — Entry point TypeScript file (e.g., src/index.ts).
  • <output.d.ts> — Path to save the generated type definitions (e.g., dist/types.d.ts).
  • --module-name <module-name> — The name of your library/module (e.g., my-lib).

2. Generate Documentation

react-tsdoc docs <path-to-root-ts> <output-folder> --module-name <module-name>

Purpose: Generates Markdown documentation in categorized folders (components, hooks, etc.).

Parameters:

  • <path-to-root-ts> — Entry point TypeScript file.
  • <output-folder> — Folder to store generated Markdown files (e.g., docs).
  • --module-name <module-name> — Your library/module name.

Supported Code Patterns

The generator supports common React patterns and outputs clear documentation for each.

Functional Components

Declared with React.FC or React.FunctionComponent.

interface ILabelProps {
  /** The label text to display */
  value: string;
}
/**
 * A simple label component
 * @export
 * @example <Label value="Hello" />
 */
const Label: React.FC<ILabelProps> = ({ value }) => <span>{value}</span>;

Class Components

Extend React.Component with props (and optional state).

interface ILabelProps {
  /** The label text to display */
  value: string;
}
/**
 * A class-based label component
 * @export
 * @example <Label2 value="Hello" />
 */
class Label2 extends React.Component<ILabelProps> {
  render() {
    return <span>{this.props.value}</span>;
  }
}

ForwardRef Components

Expose refs using React.forwardRef.

interface IRef { focus(): void; }
interface IInputProps { value: string; }
/**
 * An input with ref support
 * @export
 * @example <Input ref={ref} value="Hello" />
 */
const Input = React.forwardRef<IRef, IInputProps>((props, ref) => (
  <input ref={ref} value={props.value} />
));

Memoized Components

Use React.memo to optimize rendering.

interface IMemoProps { value: string; }
/**
 * A memoized label
 * @export
 * @example <MemoedLabel value="Hello" />
 */
const MemoLabel: React.FC<IMemoProps> = ({ value }) => <span>{value}</span>;
const MemoedLabel = React.memo(MemoLabel);

Functions & Hooks

Functions

Standalone utility functions.

/**
 * Adds two numbers
 * @export
 * @example add(2, 3) // Returns 5
 */
function add(a: number, b: number): number {
  return a + b;
}

Hooks

Custom hooks starting with use.

/**
 * Fetches data from a URL
 * @export
 * @hook
 * @example const data = useFetchData('url');
 */
function useFetchData(url: string): string {
  return "data";
}

Supported TSDoc Annotations

| Tag | Description | | ---------- | ----------------------------------------------------------------------------------------- | | @export | Marks the item for inclusion in docs and type definitions. Required for public API items. | | @example | Adds usage examples (supports multiple). | | @hook | Optional for hooks; classifies them in generated docs. |


Example Workflow

  1. Document your code with TSDoc annotations.

  2. Generate type definitions:

    react-tsdoc types src/index.ts dist/types.d.ts --module-name my-ui
  3. Generate documentation:

    react-tsdoc docs src/index.ts docs --module-name my-ui

Tips for Best Results

  • Write clear, concise comments for props, parameters, and return values.
  • Include examples that developers can copy and paste.
  • Keep your public API clean and well-annotated.

Contributing

We welcome contributions! Here’s how you can help:

  1. Report issues or suggest features on GitHub.
  2. Submit pull requests with bug fixes or enhancements.
  3. Improve this documentation with clearer examples or new sections.

Before contributing, please:

  • Fork the repository.
  • Create a new branch for your changes.
  • Ensure your code follows the existing coding style.
  • Add or update tests when applicable.

Happy documenting! 🚀