prop-types-docs
Document your prop types!
API Documentation
Installation
yarn add prop-types-docs
npm install prop-types-docs
Given the following component:
const MyComponent = { <div> name: name age: age contacts: contacts </div>}
We can document our props:
name: 'MyComponent' // optional props: name: type: PropTypesstring required: true description: "The user's name" age: type: PropTypesnumber required: true description: "The user's age" contacts: type: PropTypesarray default: description: 'A list of contacts' MyComponent
Which is the equivalent of:
MyComponentdisplayName = 'MyComponent' MyComponentpropTypes = name: PropTypesstringisRequired age: PropTypesnumberisRequired contacts: PropTypesarray MyComponentdefaultProps = contacts:
Notes
-
prop-types-docs
is not a higher order component. It simply assigns the.propTypes
and.defaultProps
on the provided component. This also allows it to be used anywhere in a compose chain. -
In addition to setting the prop types, it also stores the
props
meta object on the.propInfo
key on the provided component.
Todo
Better support for complex proptypes, e.g. arrayOf(shape())
.