Docs

Docs

  • Try Bit next-gen (beta) ⮕
  • Docs
  • Tutorials
  • Guides
  • Github

›Components

Introduction

  • Quick Start
  • Installation
  • How bit Works?
  • Bit Workspace
  • FAQ

Components

  • Tracking
  • Compiling
  • Testing
  • Versioning
  • Documenting
  • Exporting
  • Removing & Deprecating
  • Installing
  • Importing
  • Viewing

Advanced

  • Dependencies
  • Overrides
  • CI & Deployment
  • Bit Server

bit.dev

  • Functionality
  • Account
  • Authentication

Reference

  • Bit Client Configuration
  • Workspace Configuration
  • CLI Commands
  • Usage Analytics

Extending Bit

  • Extending Bit
  • Using Extensions
  • Developing Extensions
  • Build a compiler
  • Build a tester
Edit

Documenting

Documentation is an essential part of code. When creating reusable components, it is especially important, as other developers need the documentation to properly use the components in their projects.

Bit supports several methods of documenting components.

Markdown file

Use a markdown file with the documentation for each component. Bit renders the markdown file contents alongside the component as its documentation.
The markdown file should be tracked as part of the component. Use the bit add command we can append a file to a tracked component:

bit add docs/login.md --id login

The Markdown file can have any name, not only README.md.

JSDocs

JSDocs is a standard format for documenting APIs in JavaScript. Bit parses JSDocs and uses it as the component's documentation.

Here is an example for the usage of JSDocs in a component with the rendered result.

/** @flow */

/**
 * Computes the difference between two array references.
 * @name diff
 * @param {[]} firstArray
 * @param {[]} secondArray
 * @returns {[]} returns an array representing the difference between the two arrays
 * @example
 *  diff([1,2,3], [1,2,3,4,5]) // => [4,5]
 */
export default function diff(firstArray: any[], secondArray: any[]): any[] {
  return firstArray.concat(secondArray).filter((val) => {
    return !(firstArray.includes(val) && secondArray.includes(val));
  });
};

Comments in the code

Another method of documenting components is to use a JSDocs comment block to write the docs. It's possible to use markdown format in the documentation block.

/** @flow */

/**
 * # diff
 *
 * Computes the difference between two array references.
 *
 * ## Params
 *
 * - firstArray
 * - secondArray
 *
 * ## returns
 *
 * An array representing the difference between the two arrays
 *
 * ## example
 *
 * ```javascript
 *  diff([1,2,3], [1,2,3,4,5]) // => [4,5]
 * ```
 */
export default function diff(firstArray: any[], secondArray: any[]): any[] {
  return firstArray.concat(secondArray).filter((val) => {
    return !(firstArray.includes(val) && secondArray.includes(val));
  });
};
← VersioningExporting →
  • Markdown file
  • JSDocs
  • Comments in the code
Docs
bit.dev
bit.devSupportTerms and PrivacySLA
Community
SlackTwitter
More
Star
Copyright © 2022 bit.dev