default-props
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.1 • Public • Published

    Default Props

    Dependabot badge Dependencies Build Status Coverage Status

    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'] })
    }

    Install

    npm i default-props

    DownloadsWeekly Downloads

    5

    Version

    0.1.1

    License

    GPL-3.0

    Unpacked Size

    18.4 kB

    Total Files

    5

    Last publish

    Collaborators

    • iamogbz