hanki.dev

Add documentation to your component props with PropTypes

You can easily add some documentation to your components with prop-types package:

import PropTypes from 'prop-types';

const MyComponent = ({myProp}) => ...

MyComponent.propTypes = {
  /**
   *  Important info about myProp
   *
   * `code_example_on_second_line`
   */
  myProp: PropTypes.func.isRequired
};

export default MyComponent;

Then, when you use MyComponent and hover the prop, you can see your documentation.

PropTypes documentation example

#react