0.1.1 • Published 7 years ago

react-generic-proptypes v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

react-generic-proptypes

Build Status

A React Proptype Validator to check if passed prop is following generic predicates

Allows multiple validation steps with different messages

Example

var genericProptype = require('react-generic-proptypes').genericProptype;

const TestClass = React.createClass({
  propTypes : {
    testSimpleProp : genericProptype(
      'object',
      function(obj) {
        return typeof obj === 'object';
      },
      function (obj) {
        return obj && obj.foo === 456;
      }
    ),
    testComplexProp : genericProptype(
      'object',
      function(obj) {
        return typeof obj === 'object';
      },
      [
        function firstFunction(obj) {
          return true;
        },
        {
          validationPredicate: function(obj) {
            return true;
          },
        },
        {
          failureMessage: 'Custom error message appended to warning',
          validationPredicate: function shouldNeverReach(obj) {
            return true;
          },
        },
      ],
    ),
  },
  render() {
    return null;
  },
});

// Class Use
<TestClass testSimpleProp={{ 'test': 1 }}
           testComplexProp={{ foo: 456 }} />

Tests

  • npm test for running unit tests
  • npm run coverage for current test coverage