prop-types-annotated
v1.0.0
Published
Prop types, but with type metadata
Downloads
2
Readme
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.