1.0.0 • Published 6 years ago

combined-proptypes v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

combined-proptypes

Example

import PropTypes from 'prop-types';

Component.PropTypes = {
  title: PropTypes.string,
  counter: PropTypes.number,
  onPress: PropTypes.func.isRequired
};

Component.defaultProps = {
  title: "no title",
  counter: 0
};

becomes:

import { PropTypes, setPropTypes } from 'combined-proptypes';

setPropTypes(Component, {
  title: PropTypes.string("no title"),
  counter: PropTypes.number(0),
  onPress: PropTypes.func.isRequired
});

Why combined-proptypes?

  • Centralizes the setting of type and default value for props.
  • Enforces safe coding practices by requiring you to provide a default value for optional props.

Supported PropTypes

Currently the following PropTypes are supported:

PropTypes.array
PropTypes.array.isRequired
PropTypes.string
PropTypes.string.isRequired
PropTypes.bool
PropTypes.bool.isRequired
PropTypes.func
PropTypes.func.isRequired
PropTypes.number
PropTypes.number.isRequired
PropTypes.object
PropTypes.object.isRequired
PropTypes.symbol
PropTypes.symbol.isRequired

More PropTypes might follow if I get around to it ;)