NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm, #2142 most downloaded on npm
A library to extract information from React components for documentation generation.
Latest stable
8.0.4
Last release 2 months ago
20 Sep 2026
Release timing varies
gaps range from 2 weeks to 10 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
99 releases · first in 2015
Drag across the ruler to compare, or tap a release to open it.
Add support for typeof types and React.* types
Add support for typeof types and React.* types (#224)
Adds support for all the types described in the react flow docs
Resolve flow $Keys<> to union type (#225)
const CONTENTS = {
'apple': '🍎',
'banana': '🍌',
};
type Props = {
fruit: $Keys<typeof CONTENTS>,
};
The names of class declarations and function declarations are now used as displayNames (3f22b3c49f4056ad725bec8d9908cc1027bf45dc).
The names of class declarations and function declarations are now used as displayNames (3f22b3c49f4056ad725bec8d9908cc1027bf45dc).
In classes, static get propTypes(){} is now inspected for propTypes. I.e. instead of
class MyComponent extends React.Component {}
MyComponent.propTypes = {
disabled: PropTypes.boolean,
};
you can now write
class MyComponent extends React.Component {
static get propTypes() {
return {
disabled: PropTypes.boolean,
};
}
}
(23aa0feeff512ea841907e75598798de65bedd4a)
resolveToModule also resolvesJSXIdentifiers now (2c6e55aa838c1cb9a6755711a17ca4f108cbdf13)Your coding agent can read these notes before it upgrades. Set up the MCP server →
Add support for flow >=0.53 and the new react definitions (#209).
Object.keys in PropType.oneOf() (#211).
For example:Component.propTypes = { foo: PropTypes.oneOf(Object.keys({ a: 1, b: 2 }))};
// react-docgen will now correctly extract the type of foo being "a" or "b"
Classes that define a render *public class field* are now considered React components. For example: ` class Component extends SomeBaseComponent { rend
Classes that define a render public class field are now considered React components. For example:
class Component extends SomeBaseComponent {
render = someFunction;
}
See #193 and fe55485. Thank you @birjolaxew!
Functions assigned to public class fields are now considered as methods. I.e. both function in the following example will be picked up by react-docgen:
class Component extends React.Component {
method1() {}
method2 = () => {
};
}
See 1ff84b7 and #182.
recast ( 760c426 ).-e, --exclude now accepts a regular expression to filter out files by name: -e /.*-test\.js/ The argument will only be treated as a regular expression
-e, --exclude now accepts a regular expression to filter out files by name: -e /.*-test\.js/ The argument will only be treated as a regular expression if the parameter is only passed once ( #164).Thank you @wallaroo for your contribution!
@wcjordan added support for the create-react-class module!
create-react-class module! ( #179 )Revert Babel setting changes ( #174 , #175 , @danez )
Added support for `developit/proptypes` ( #163, @eduardoboucas) and `prop-types` ( #172, @sawyerh) packages.
developit/proptypes ( #163, @eduardoboucas) and prop-types ( #172, @sawyerh) packages.React.Children.only as React components ( #169, @damian )coverage/ folder when publishing to npm, reducing package size by more than 50%! ( #166, @fabiosantoscode )Ignore __mocks__ directories by default (#135) (@aitherios)
__mocks__ directories by default (#135) (@aitherios)React.cloneElement as stateless components (#138) (@khankuan)Fixed an issue where props without default value would be reported as having computed default values. This only affected stateless components. Reporte
Support for objectOf prop type (86b167f) (reported as #74)
objectOf prop type (86b167f) (reported as #74)When passing an unknown value to shape(...), react-docgen will now report that value as computed.
Example: shape(Child.propTypes)
Before:
"type": {
"name": "shape",
"value": "unkown"
}
Now:
"type": {
"name": "shape",
"value": "Child.propTypes",
"computed": true
}
(eb0edaa) (reported as #87)
Resolve static values passed to oneOf. Examples:
React.PropTypes.oneOf([TYPES.FOO, TYPES.BAR]);
// or:
var TYPES = ["FOO", "BAR"];
React.PropTypes.oneOf(TYPES);
// or:
var TYPES = ["A", "B"];
var MORE = [...TYPES, "C"];
React.PropTypes.oneOf(MORE);
(#122, @ZauberNerd)
Until now, react-docgen didn’t find components that are passed to a higher order component (HOC):
Until now, react-docgen didn’t find components that are passed to a higher order component (HOC):
function MyComponent() { /* ... */ }
export default hoc(MyComponent);
The workaround was to change the resolver to find all component definitions in the file, something that is not always desirable.
With #124, @rtsao extended the default resolver to be able to handle these cases.
findAllExportedComponentDefinitions can now be selected in the CLI.
(reported as issue #119)
The static variable resolution process was fixed to consider assignments to variables. The following example didn’t work before and works now:
var Component;
Component = React.createClass(...);
module.exports = Component;
(reported as issue #58)
The display name handler now takes displayName getters in class definitions into account:
class Component extends React.Component {
static get displayName() {
return 'Name';
}
}
(reported as issue #61)
To guard ourselves better against regressions, we are using jest’s snapshot tests to test component definitions that are reported as broken.
New findAllExportedComponentDefinitions resolver. As the name suggests, it finds all _exported_ component definitions. This complements the resolvers
findAllExportedComponentDefinitions resolver. As the name suggests, it finds all exported component definitions. This complements the resolvers for finding all component definitions and the default exported definition ( #114, @ZauberNerd )-e, --exclude PATTERN, allows you to skip files that match the provided pattern ( #102, @wallaroo )MemberExpressions (such as propTypes of a stateless component) to the correct object ( #111, @ZauberNerd )imported value, the value of the prop will now be the variable name ( #99 , @nathanmarks )@param {x|y} and @param {*} now correctly resolve to their equivalent flow type declarations (union and mixed). ( #95 , @dickeylth )Thanks to everyone who contributed, this is great!
Handling of optional JSDoc types ( @caabernathy , #89 )
@caabernathy added new information to method parameters ( #83 ). If the parameter has a flow type, the name of the type is no also included. I.e. if t
@caabernathy added new information to method parameters ( #83 ). If the parameter has a flow type, the name of the type is no also included. I.e. if the type definition is:
export type StatusBarStyle = $Enum<{
...
}
the docs for a parameter of that type will include alias: "StatusBarStyle".
In addition the docs now include an optional field indicating whether the parameter is optional or nor.
Better handling of method parameters
I believe publishing 2.8.0 to npm didn't work properly, so this just to ensure that there is a working version in npm.
I believe publishing 2.8.0 to npm didn't work properly, so this just to ensure that there is a working version in npm.
No changes in this release.
@janicduplessis added support for extracting documentation about custom React component methods ( #66 ).
@janicduplessis added support for extracting documentation about custom React component methods ( #66 ).
This version adds a great new feature: Support for Flow type definitions. Thanks a lot to @danez for implementing this feature ( #48 ).
This version adds a great new feature: Support for Flow type definitions. Thanks a lot to @danez for implementing this feature ( #48 ).
react-docgen is now able to extract type definitions as in this example:
import React, { Component } from 'react';
type Props = {
/** Description of prop "foo". */
primitive: number,
/** Description of prop "bar". */
literalsAndUnion: 'string' | 'otherstring' | number,
arr: Array<any>,
func?: (value: string) => void,
obj?: { subvalue: ?boolean },
};
/**
* General component description.
*/
export default class MyComponent extends Component<void, Props, void> {
props: Props;
render(): ?ReactElement {
// ...
}
}
In the JSON output, every prop will have a new field named flowType. If you use both, flow (for static type checks) and React propTypes (for dynamic type checks) you can do so without any collisions. The JSON blob now simply contains more information and you can decide which one to use for your documentation.
Have a look at the more extensive description in the README to learn how flow types are represented.
propTypeHandler now ignores nodes that are not ObjectExpressions. If there was something else, e.g.
propTypeHandler now ignores nodes that are not ObjectExpressions. If there was something else, e.g.
propTypes: Foo.bar,
propTypeHandler used to throw an error.
Fixed docblock parsing for stateless named functions (function declarations) used as default exports ( #51, 0b8546acf1e52e73093696e45afd4947c83ece32 )
Fix docblock extraction for classes with decorators ( #49 , 44777a9040b7bde9498ee8cf0a527a4c747a6955 )
The --resolver lets you specify from the CLI which resolver * to use. It can either be the name of a built-in resolver or a path to a JavaScript modul
--resolver CLI optionThe --resolver lets you specify from the CLI which resolver<sup>*</sup> to use. It can either be the name of a built-in resolver or a path to a JavaScript module that exports a resolver function:
react-docgen --resolver findExportedComponentDefinition ./path/to/component.js
# same as
react-docgen ./path/to/component.js
react-docgen --resolver findAllComponentDefinitions ./path/to/component.js
react-docgen --resolver ./path/to/custom/resolver.js ./path/to/component.js
* Resolvers contain the logic to find React component definitions in the JavaScript files.
Better support for React Native
Variables used for propTypes and defaultProps, e.g.
MyClass.defaultProps = defaultProps;
are now properly resolved for class and stateless components. Thanks to @oliviertassinari for reporting this issue! ( #45, #46 )
Since React v0.14, components can be defined as simple functions:
Since React v0.14, components can be defined as simple functions:
function SimpleComponent(props) {
return <div>{this.props.soSimple}</div>
}
Thanks to @iamdustan, react-docgen is now able to detect these components as well. The findExportedComponentDefinition and findAllComponentDefinitions have been updated accordingly.
A function is considered to be a stateless React component if we can determine that it returns a JSX element or the result of a React.createElement call. As always, there are limits to what can be achieved with static analysis, so it might not detect every possible case (but maybe your component is too complex then anways? ;) ).
The `propTypeCompositionHandler` was not part of the default handlers and therefore the generated documentation didn't contain information about compo
The propTypeCompositionHandler was not part of the default handlers and therefore the generated documentation didn't contain information about composition.
Now parses code that uses do expressions or function bindings (https://github.com/reactjs/react-docgen/pull/32).
(I wasn't sure whether this should be considered to be a bug fix or new feature, but I went with new feature instead)
(I wasn't sure whether this should be considered to be a bug fix or new feature, but I went with new feature instead)
Consider docblock above decorator annotations (#18). In the following example the docblock is now used for the component description:
/**
* This is the description
*/
@SomeDecorator
export default class extends React.Component {
};
Detect isRequired in shape annotations (second part of #21)
Nothing published for this version
defaultPropHandler throws error when encountering non-Property node
"Short" docblocks are now recognized (#20, d3a3f3f64d3642659c224d8fbc31fe53e8d855a9):
"Short" docblocks are now recognized (#20, d3a3f3f64d3642659c224d8fbc31fe53e8d855a9):
/** Short docblock */
Docblocks on shape fields are now added to the output (#21, f5415ced5c4b6eb604b4c39093b8875d29a12239):
React.PropTypes.shape({
/**
* Field description
*/
field: React.PropTypes.string
});
produces
{
name: 'shape',
value: {
field: {
name: 'string',
description: 'Field description',
}
}
Updated dependencies \[`2b51bbd`]:
The minimum supported version is now 16.14.0
react-docgen is now able to find components defined as ES2015 classes. A class either has to extend React.Component or has to define a render() method in order to be recognized as React component.
Examples:
class Component extends React.Component {
// ...
}
class Component {
render() {
// ...
}
}
are both considered React components. The default resolvers have been updated and renamed accordingly.
For propTypes, defaultProps and other properties, react-docgen supports class properties (ES7 stage 0 proposal at the moment of this release) and assignments to the constructor function. Example:
class Component extends React.Component {
static propTypes = { ... };
}
// or
class Component extends React.Component {
// ...
}
Component.propTypes = { ... };
displayNameHandlerThis new default handler adds the displayName of a component to the documentation. Example:
var Component = React.createClass({
displayName: 'Foo',
});
class Component extends React.Component {
// ...
}
Component.displayName = 'Foo';
will result in the documentation object {displayName: 'Foo'}.
The props and description properties are now not present anymore if no props or description could be extracted from the definition. I.e. instead of getting :
{
"description": "",
"props": {}
}
(like it is now), you would get
{}
This makes it easier to test for the existence of props in the first place:
if (doc.props) {
// component has props, render them
}
Documentation classThe setDescription and getDescription methods are gone. Instead we added the generic set(key, value) and get(key) method. This allows custom handlers to add arbitrary data to the documentation. Data set this way will be added as properties to the result documentation object.
E.g. if a handler calls documentation.set('foobar', 42), the output will be
{
"foobar": 42
}
getMemberPathValue is a new function which helps handlers to process component definitions, irrespectively if the definition is a React.createClass({}) call or a class Component {} declaration.
Because react-docgen uses Babylon (Babel's parser) instead of esprima-fb now, custom handlers/resolvers might have to be updated because of slight AST representation differences.
react-docgen now understands the following constructs:
react-docgen now understands the following constructs:
import foo from 'Foo';
import {foo} from 'Foo';
import {foo as bar} from 'Foo';
export var Component = React.createClass({});
var Component = React.createClass({});
export {Component};
export {Component as Foo};
export default Component;
export default React.createClass({});
You will now be able to use ES6 import and export declarations with your react components. However, to "detect" a React component, React.createClass(...) must still be present in the source.
Add support for destructuring assignments
Extract composition detection logic from propTypeHandler into propTypeCompositionHandler. propTypeHandler still delegates to propTypeCompositionHandle
propTypeHandler into
propTypeCompositionHandler. propTypeHandler still delegates to
propTypeCompositionHandler for backwards compatibility.defaultHandlers on the root
object.Updated dependencies \[`c7e2bd5`]:
c7e2bd5]:
Does not support input via stdin anymore
#693
3b28f6e
Thanks @danez! - Introducing the new CLI package
@react-docgen/cli which was extracted from react-docgen and is a complete
rewrite. Compared to the old CLI these are some of the major differences:
-x, --extension was removed in favor of globs-e, --exclude was removed-i, --ignore now accepts a glob--handler added--importer added--failOnWarning addedCheck out https://react-docgen.dev/docs/getting-started/cli for the documentation.
#714
80e4c74
Thanks @danez! - Renamed --handlers option to
--handler. This unifies all options to be singular.
#714
80e4c74
Thanks @danez! - --resolver option can now be
used multiple times.
If used multiple times the resolvers will be chained in the defined order and all components from all resolvers will be used.
#753
217a005
Thanks @danez! - Add support for the
FindAnnotatedDefinitionsResolver.
Can be used with
react-docgen --resolver find-all-annotated-components
ebd9130
Thanks @danez! - Display the correct help info
when running react-docgen --help
#782
72ac984
Thanks @renovate! - Update dependency
commander to v10.0.1
050313d
Thanks @danez! - Correctly add LICENSE file to
published packages
#792
e0999e1
Thanks @renovate! - update dependency
slash to v5.1.0
#783
fc8a97c
Thanks @renovate! - update dependency
slash to v5.0.1
#729
5b281f4
Thanks @renovate! - update dependency
commander to v10
Updated dependencies
[96d6e9e,
96d6e9e,
8fe3dbf,
d7a39af,
7c99f15,
dfc2f85,
96d6e9e,
96d6e9e,
96d6e9e,
96d6e9e,
0a2481d,
0a2481d,
96d6e9e,
caae6bf,
80e4c74,
96d6e9e,
e956802,
96d6e9e,
96d6e9e,
96d6e9e,
96d6e9e,
a684d82,
96d6e9e,
96d6e9e,
cc94da2,
98a1138,
80e4c74,
3b28f6e,
96d6e9e,
96d6e9e,
ea25b16,
5a226ac,
96d6e9e,
96d6e9e,
96d6e9e,
1aa0249,
0a2481d,
96d6e9e,
050313d,
96d6e9e,
96d6e9e,
5215bab,
f6e4fe7,
5215bab,
80e4c74,
96d6e9e,
d4c27d4,
96d6e9e,
e08e08d]:
One column per quarter.