prop-types-annotated

1.0.0 • Public • Published

prop-types-annotated

A tiny wrapper around the PropTypes library that does not change its functionality, but provides some extra metadata on a React component's prop types.

For example, if you have a component like this:

import React from 'react';
import PropTypes from 'annotated-prop-types';

export default MyComponent extends React.Component {
  static propTypes = {
    name: PropTypes.string.isRequired
  };

  render() {
    return <h1>hello {this.props.name}!</h1>;
  }
}

Then, elsewhere, you could import this component and get some information from its propTypes:

import MyComponent from './my-component';

console.log(MyComponent.propTypes.name.metadata);
// -> {type: "string", isRequired: true}

This is especially helpful when generating documentation (e.g. props tables) straight from a component's source code.

Readme

Keywords

none

Package Sidebar

Install

npm i prop-types-annotated

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

6.02 kB

Total Files

4

Last publish

Collaborators

  • reid47