JSPM

default-props

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q54711F
  • License GPL-3.0

Auto populate default props for react components

Package Exports

  • default-props

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (default-props) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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