defaultPropsHandler

Finds the default props from the react component and adds it to the documentation. Supported variants are:

  • The static property named defaultProps in Class components
  • Assignment of the static property defaultProps on Class or Function components
  • Default values in destructuring the prop argument in Function components

Examples

When the defaultPropsHandler is active any of these components will result in the output below

component.tsx
class MyComponent extends React.Component {
  static defaultProps = {
    a: '1',
  };
  render() {
    return <div />;
  }
}
component.tsx
class MyComponent extends React.Component {
  render() {
    return <div />;
  }
}
 
MyComponent.defaultProps = {
  a: '1',
};
component.tsx
const MyComponent = () => <div />;
 
MyComponent.defaultProps = {
  a: '1',
};
component.tsx
({ a = '1' }) => <div />;

Output

JSON
[
  {
    "props": {
      "a": {
        "defaultValue": {
          "value": "'1'",
          "computed": false
        },
        "required": false
      }
    }
  }
]