react-generic-proptypes

    0.1.1 • Public • Published

    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

    Install

    npm i react-generic-proptypes

    DownloadsWeekly Downloads

    0

    Version

    0.1.1

    License

    MIT

    Last publish

    Collaborators

    • caleb.morris