default-props
v0.1.1
Published
Auto populate default props for react components
Downloads
30
Readme
Default Props
Auto populate default props for react components
Usage
npm i default-props
import * as PropTypes from 'prop-types'
import { defaultProps } from 'default-props'
function Component(props) {
return <abc {...props} />
}
Component.propTypes = {
b: PropTypes.bool,
n: PropTypes.number,
f: PropTypes.func,
s: PropTypes.string,
}
Component.defaultProps = defaultProps(Component)
You can also selectively combine props
Component.defaultProps = {
...defaultProps({ ...Component, keys: ['n', 's'] })
...defaultProps({ ...Component, defaults: false, keys: ['b'] })
...defaultProps({ ...Component, defaults: () => {}, keys: ['f'] })
}