react-desc
Add an schema to your React components based on React PropTypes.
Installation
Usage
Adding documentation
Accessing documentation
-
JSON output
Expected output:
-
Markdown output
Expected output:
API
-
describe(component)
Creates a proxy to the actual react component with support for the following functions:
- availableAt([{ badge: string, url: string }]): function that receives an object or an array of objects that will render where the component is available.
- description(value): function that receives a string with the component description.
- deprecated(value): function that receives a string with the deprecation message.
- toJSON(): function that returns the component schema as a JSON object.
- toMarkdown(): function that returns the component schema as a Markdown string.
- usage(value): function that receives a string with the component usage example.
-
PropTypes
Proxy around the React propTypes, all properties are supported. See all options here.
This proxy supports the following functions:- defaultValue(value): function that receives a value that represents the default prop.
- description(value): function that receives a string with the PropType description.
- deprecated(value): function that receives a string with the deprecation message.
- format(value): function that receives a string with the PropTypex format.
Why not react-docgen?
react-docgen is a great project but it relies on an AST parser to generate documentation. Most of the time this is ok, but for us the following use cases were hard to solve without a more verbose way to define propTypes:
-
Define deprecated properties
-
Define a required property for custom function:
-
Allow internal comments for properties without it showing up in the documentation