$ cnpm install prop-types-docs
yarn add prop-types-docs
npm install prop-types-docs
const MyComponent = ({ name, age, contacts }) => {
<div>
name: {name}
age: {age}
contacts: {contacts.map(() => ...)}
</div>
}
import PropTypes, { withPropDocs } from 'prop-types-docs'
export default withPropDocs({
name: 'MyComponent', // optional
props: {
name: {
type: PropTypes.string,
required: true,
description: "The user's name",
},
age: {
type: PropTypes.number,
required: true,
description: "The user's age",
},
contacts: {
type: PropTypes.array,
default: [],
description: 'A list of contacts',
},
},
})(MyComponent)
import PropTypes from 'prop-types'
MyComponent.displayName = 'MyComponent'
MyComponent.propTypes = {
name: PropTypes.string.isRequired,
age: PropTypes.number.isRequired,
contacts: PropTypes.array,
}
MyComponent.defaultProps = {
contacts: [],
}
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.
Better support for complex proptypes, e.g. arrayOf(shape())
.
Copyright 2014 - 2017 © taobao.org |