Simple, precise, and chainable React Custom PropTypes.
npm install react-custom-proptypessh
$ npm install react react-dom react-custom-proptypes --save
`
createPropType
$3
`
createPropType(callback[, description])
`
$3
##### callback : function
Function that returns a boolean representing the validation of the proptype, taking a single argument: prop, the value of the prop
##### description : string
Optional. Use this value to specify a helpful description.
$3
`jsx
import React from 'react';
import { createPropType } from 'react-custom-proptypes';
const Card = props => (
{props.suit}
{props.value}
);
const suitPropType = createPropType(
prop =>
prop === 'spades' ||
prop === 'hearts' ||
prop === 'diamonds' ||
prop === 'clubs',
'Must be spades, hearts, diamonds, or clubs.'
);
const valuePropType = createPropType(
prop =>
Number.isInteger(prop) &&
prop >= 1 &&
prop <= 12,
'Must be an integer from 1 - 12.'
);
Card.propTypes = {
suit: suitPropType.isRequired,
value: valuePropType.isRequired
};
export default Card;
`
createIteratorPropType
$3
`
createIteratorPropType(callback[, description])
`
$3
##### callback : function
Function that returns a boolean representing the validation of the proptype, taking two arguments:
* prop - the value of the prop
* key - the key of the current element being processed in the iterable object.
##### description : string
Optional. Use this value to specify a helpful description.
$3
`jsx
import React, { PropTypes } from 'react';
import { createIteratorPropType } from 'react-custom-proptypes';
const TweetFeed = props => (
{props.tweets.map((tweet, index) => (
{tweet}
))}
);
TweetFeed.propTypes = {
tweets: PropTypes.arrayOf(createIteratorPropType(
prop => typeof prop === 'string' && prop.length < 140
)).isRequired
};
export default TweetFeed;
`
Contributing
Issues and pull requests are welcome.
`sh
$ git clone https://github.com/jackrzhang/react-custom-proptypes
$ cd react-custom-proptypes
$ npm install
`
Please run linting and tests prior to commits.
`sh
$ npm run lint
$ npm test
``