1.0.0 • Published 8 years ago

react-docgen-exports-handler v1.0.0

Weekly downloads
11
License
MIT
Repository
github
Last release
8 years ago

react-docgen-exports-handler Build Status

A handler for react-docgen that finds the format, type and name of the export definition for a component.

Rationale

react-docgen is a CLI and API toolbox to help extract information from React components and generate documentation from it.

react-docgen-exports-handler is a custom handler for react-docgen and can be used to find the format (ES2015 or CommonJS), the type (default or named) and the name (if it is not a default export) of an exported component.

Installation

Install react-docgen-exports-handler from npm

npm install --save react-docgen-exports-handler

Usage

Unfortunately there is currently no easy way to use custom handlers with the react-docgen CLI.

Discussions and Ideas about how to make this easier are happening in the react-docgen issue discussions.

If you want to use this module programmatically check out the react-docgen API docs for more information about the react-docgen API.
Below is a small example that demonstrates how to integrate react-docgen-exports-handler.

import reactDocs from 'react-docgen';
import exportsHandler from 'react-docgen-exports-handler';
const resolver = reactDocs.resolver.findExportedComponentDefinition;
const handlers = reactDocs.handlers.concat(exportsHandler);
const documentation = reactDocs.parse(src, resolver, handlers);

Examples

When using this custom handler with react-docgen it will try to find the export definition for the component definition.

import React from 'react';
export default function() { return <button />; }
{
  "exports": {
    "format": "ES2015",
    "type": "default",
    "name": ""
  },
  "props": {...}
}

For more information about the data format see the react-docgen readme