Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-react-docgen

Package Overview
Dependencies
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-docgen

Babel plugin to add react-docgen info into your code

  • 4.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
decreased by-1.6%
Maintainers
3
Weekly downloads
 
Created

What is babel-plugin-react-docgen?

The babel-plugin-react-docgen npm package is a Babel plugin that extracts type and prop information from React components. It uses the react-docgen library to parse and collect documentation from React component files, which can then be used to generate documentation or for other purposes in the development workflow.

What are babel-plugin-react-docgen's main functionalities?

Extracting prop types information

This feature allows you to automatically extract prop types information from your React components. The plugin will parse the propTypes definition and attach it to the component object, which can then be used for documentation purposes.

import React from 'react';
import PropTypes from 'prop-types';

class MyComponent extends React.Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
    age: PropTypes.number
  };

  render() {
    return <div>{this.props.name}</div>;
  }
}

Extracting default prop values

This feature extracts the default values for props defined in a React component. The plugin will parse the defaultProps definition and attach it to the component object, which can be used to enhance the generated documentation with default values for each prop.

import React from 'react';
import PropTypes from 'prop-types';

class MyComponent extends React.Component {
  static propTypes = {
    name: PropTypes.string
  };

  static defaultProps = {
    name: 'Default Name'
  };

  render() {
    return <div>{this.props.name}</div>;
  }
}

Extracting component description

This feature extracts the description of the component which is provided in the comment block above the component declaration. This description can then be included in the generated documentation to provide more context about the component's purpose and usage.

/**
 * This is MyComponent.
 * It is an example component.
 */
import React from 'react';

class MyComponent extends React.Component {
  render() {
    return <div>Hello, World!</div>;
  }
}

Other packages similar to babel-plugin-react-docgen

Keywords

FAQs

Package last updated on 12 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc