Package Exports
- react-custom-proptypes
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 (react-custom-proptypes) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React Custom PropTypes exposes a simple API for creating precisely defined, dependency-free, and chainable React PropType validators.
Check out the examples for various use cases.
##Installation
$ npm install react react-dom react-custom-proptypes --save##API
###createPropType
####Syntax:
createPropType(callback[, message])####Usage:
import React from 'react';
import { createPropType } from react-custom-proptypes';
const Tweet = props => (
<div>{props.text}</div>
);
Tweet.propTypes = {
text: createPropType(
prop => typeof prop === 'string' && prop.length < 140
).isRequired
};####Parameters
#####callback : function
Function that returns a boolean representing the validation of the proptype, taking a single argument: prop, the value of the prop
#####message : string
Optional. Use this value to specify a custom error message.
###createIteratorPropType
####Syntax:
createIteratorPropType(callback[, message])####Usage:
import React, { PropTypes } from 'react';
import { createIteratorPropType } from 'react-custom-proptypes';
const TweetFeed = props => (
<div>
{props.tweets.map((tweet, index) => (
<div key={index}>{tweet}</div>
))}
</div>
);
TweetFeed.propTypes = {
tweets: PropTypes.arrayOf(createIteratorPropType(
prop => typeof prop === 'string' && prop.length < 140
)).isRequired
};
export default TweetFeed;####Parameters
#####callback : function
Function that returns a boolean representing the validation of the proptype, taking two arguments:
prop- the value of the propkey- the key of the current element being processed in the iterable object.
#####message : string
Optional. Use this value to specify a custom error message.
##Contributing Issues and pull requests are welcome.
$ git clone https://github.com/jackrzhang/react-custom-proptypes
$ cd react-custom-proptypes
$ npm installPlease run linting and tests prior to commits.
$ npm run lint
$ npm test##License MIT