Skip to content

CalebMorris/react-generic-proptypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published