Topics

On this page

Last updated on Dec 5, 2025

Documentation

Good documentation makes a project easier to use, maintain, and contribute to. In React projects, documentation spans components, code, commits, and project-level files.

Component documentation

Storybook

Storybook is the recommended tool for documenting React components.It lets you preview components in isolation without needing to run the entire application, see all possible states, and generate interactive docs.

A “story” represents a single visual state of a component. For a simple example, let’s assume a simple Button component. The story will look like this.

import { Button } from './Button';

// The default export metadata for the component
export default {
  title: 'UI/Button',         // Title in the Storybook sidebar (use '/' for nesting)
  component: Button,          // The component itself
  tags: ['autodocs'],         // Enables automatic documentation generation
  argTypes: {                 // Controls for props in the Storybook UI
    backgroundColor: { control: 'color' },
  },
};

// Stories
export const Primary = {
  args: {
    primary: true,
    label: 'Button',
  },
};

export const Secondary = {
  args: {
    label: 'Button',
  },
};

export const Large = {
  args: {
    size: 'large',
    label: 'Button',
  },
};

export const Small = {
  args: {
    size: 'small',
    label: 'Button',
  },
};

By adding tags: ['autodocs'] to your default export, Storybook automatically creates a beautiful documentation page for your component. This page includes:

Code comments

Do 👍Don’t 👎
Comment on the “why,” not the obvious “what.”Don’t comment what the code obviously does.
Write comments for complex or non-obvious logic.Don’t leave commented-out code in the codebase.
Use comments to warn about consequences.Don’t write comments that are out of date or incorrect.
Use TODO and FIXME to mark future work.Don’t use comments for version history or attribution.
Write formal documentation for public APIs.Don’t write “closing brace” comments (// end if).
Focus on writing clean, self-documenting code first.Don’t try to make up for bad code with lots of comments.
Treat comments as part of the code; keep them up-to-date.Don’t clutter the code with noise.

Code commits

A frequently overlooked type of documentation is the commit message. We like to follow the best practices mentioned in the Conventional commit doc

Project documentation

There should be 3 main files documenting a project

README.md

The first place anyone will see when interacting with the project. Treat it like a front page for developers. A good README should have the following – 

CONTRIBUTING.md

This file explains the “rules of the road” for developers who want to contribute code.

CHANGELOG.md

A chronological log of user-facing changes for each version of the project. This is invaluable for both developers and stakeholders. Look at keepachangelog for a format to base the CHANGELOG on.

With these practices:


Credits

Authored by Sayed Sayed Sayed Taqui Director of Engineering – React , Imran Imran Imran Sayed Senior WordPress Engineer , Ayush Ayush Ayush Nirwal Senior Software Engineer , Amoghavarsha Amoghavarsha Amoghavarsha Kudaligi Senior Software Engineer , Mayank Mayank Mayank Rana Senior Software Engineer