GithubHelp home page GithubHelp logo

prop-types's Introduction

prop-types Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

Custom React PropType validators that we use at Airbnb. Use of airbnb-js-shims or the equivalent is recommended.

  • and: ensure that all provided propType validators pass
    • foo: and([number, nonNegativeInteger])
  • between: provide an object with an gt or gte number, and an lt or lte number (only one item allowed from each pairs; one or both pairs may be provided), and the resulting propType validator will ensure the prop value is a number within the given range. Alternatively, you can provide a function that takes the props object and returns a number for each of the gt/gte/lt/lte values.
    • foo: between({ gte: 0, lte: 5 })
    • foo: between({ gt: 0, lt: 5 })
  • booleanSome: provide a list of props, and all must be booleans, and at least one of them must be true.
    • foo: booleanSome('small', 'medium', 'large')
  • childrenHavePropXorChildren: ensure that either all children have the indicated prop, all children have children, or all children have neither.
    • foo: childrenHavePropXorChildren('bar')
  • childrenOf: restrict the children prop to only allow children that pass the given propType validator.
    • children: childrenOf(number.isRequired)
  • childrenOfType: restrict the children prop to only allow children of the given element types - takes a Component, an HTML tag name, or "*" to match everything.
    • children: childrenOfType('span')
    • children: childrenOfType(Component)
  • childrenSequenceOf: restrict the children prop to be a sequenceOf the given "specifiers" (see sequenceOf)
    • children: childrenSequenceOf({validator: string, min: 0, max: 5})
  • componentWithName: restrict the prop to only allow a component with a certain name/displayName. Accepts a string, or a regular expression. Also accepts an options object with an optional stripHOCs array of string HOC names to strip off before validating; an HOC name must not contain parentheses and must be in camelCase.
    • foo: componentWithName('Component')
    • foo: componentWithName('Component', { stripHOCs: ['withDirection', 'withStyles'] })
  • disallowedIf: restrict the prop from being provided if the given other prop name matches the given other prop type. The other prop type validator only applies if the other prop name is not a null value.
    • foo: disallowedIf(string, 'bar', bool)
  • elementType: require that the prop be a specific type of React element - takes a Component, an HTML tag name, or "*" to match everything.
    • foo: elementType('span')
    • foo: elementType(Component)
  • empty: a value that React renders to nothing: undefined, null, false, the empty string, or an array of those things.
    • foo: empty()
  • explicitNull: only allow null or undefined/omission - and only null when required.
    • foo: explicitNull()
  • forbidExtraProps: pass your entire propTypes object into this function, and any nonspecified prop will error.
    • Component.propTypes = forbidExtraProps({foo: number.isRequired})
  • integer: require the prop be an integer.
    • foo: integer()
  • keysOf: pass in a proptype, and require all the keys of a prop to have that type
    • foo: keysOf(number)
  • mutuallyExclusiveProps: provide a propType, and a list of props, and only one prop out of the list will be permitted, validated by the given propType.
    • foo: mutuallyExclusiveProps(bool, 'bar', 'sna')
  • mutuallyExclusiveTrueProps: provide a list of props, and all must be booleans, and only one is allowed to be true.
    • foo: mutuallyExclusiveTrueProps('bar', 'sna')
  • nChildren: require a specific amount of children.
    • children: nChildren(3)
    • children: nChildren(3, childrenOfType('span'))
  • nonNegativeInteger: require that the prop be a number, that is 0, or a finite positive integer.
    • foo: nonNegativeInteger()
  • nonNegativeNumber: require that the prop be a number, that is 0, or a finite positive number.
    • foo: nonNegativeNumber()
  • numericString: require the prop be a string that is conceptually numeric.
    • foo: numericString()
  • object: same as PropTypes.object, but can be called outside of React's propType flow.
  • or: recursively allows only the provided propTypes, or arrays of those propTypes.
    • foo: or([bool.isRequired, explicitNull()])
  • predicate: provide a predicate function, and an optional message, and will fail when the predicate returns false.
    • foo: predicate((x) => x % 2 === 0, 'must be an even integer')
  • range: provide a min, and a max, and the prop must be an integer in the range [min, max)
    • foo: range(-1, 2)
  • ref: require the prop to be a React ref. These can be either the object returned from React.createRef() or "callback" refs.
    • foo: ref()
  • requiredBy: pass in a prop name and propType, and require that the prop is defined and is not its default value if the passed in prop name is truthy. if the default value is not provided, defaults to checking against null.
    • foo: requiredBy('bar', bool)
  • restrictedProp: this prop is not permitted to be anything but null or undefined.
    • foo: restrictedProp()
    • foo: restrictedProp(new TypeError('Custom Error'))
  • sequenceOf: takes 1 or more "specifiers": an object with a "validator" function (a propType validator), a "min" nonNegativeInteger, and a "max" nonNegativeInteger. If both "min" and "max" may be omitted, they default to 1; if only "max" is omitted, it defaults to Infinity; if only "min" is omitted, it defaults to 1.
    • foo: sequenceOf({validator: string, min: 0, max: 5})
  • shape: takes a shape, and allows it to be enforced on any non-null/undefined value.
    • foo: shape({ length: oneOf([2]) })
  • stringEndsWith: takes a non-empty string, and returns a validator that ensures the prop value is a string that ends with it.
    • foo: stringEndsWith('.png')
  • stringStartsWith: takes a non-empty string, and returns a validator that ensures the prop value is a string that starts with it.
    • foo: stringStartsWith('prefix-')
  • uniqueArray: this prop must be an array, and all values must be unique (determined by Object.is). Like PropTypes.array, but with uniqueness.
    • foo: uniqueArray()
  • uniqueArrayOf: uniqueArray, with a type validator applied. Like PropTypes.arrayOf, but with uniqueness. Can also take an optional mapper function that allows for a non-standard unique calculation (otherwise, Object.is is used by default). The function is applied to each element in the array, and the resulting values are compared using the standard unique calculation.
    • foo: uniqueArrayOf(number)
    • foo: uniqueArrayOf(element => element ** 2)
    • foo: uniqueArrayOf(element => element ** 2, 'test')
    • foo: uniqueArrayOf(array, element => element[0] ** 2, 'test')
  • valuesOf: a non-object requiring PropTypes.objectOf. Takes a propType validator, and applies it to every own value on the propValue.
    • foo: valuesOf(number)
  • withShape: takes a PropType and a shape, and allows it to be enforced on any non-null/undefined value.
    • foo: withShape(array, { length: oneOf([2]) })

Production

Since PropTypes are typically not included in production builds of React, this library’s functionality serves no useful purpose. As such, when the NODE_ENV environment variable is "production", instead of exporting the implementations of all these prop types, we export mock functions - in other words, something that ensures that no exceptions are thrown, but does no validation. When environment variables are inlined (via a browserify transform or webpack plugin), then tools like webpack or uglify are able to determine that only the mocks will be imported - and can avoid including the entire implementations in the final bundle that is sent to the browser. This allows for a much smaller ultimate file size, and faster in-browser performance, without sacrificing the benefits of PropTypes themselves.

Tests

Clone the repo, npm install, npm run react, and run npm test

prop-types's People

Contributors

ahuth avatar brucewpaul avatar gilbox avatar greenkeeperio-bot avatar hawkeyepierce89 avatar knowler avatar lifeiscontent avatar ljharb avatar merlinstardust avatar mhchen avatar raejin avatar sibnerian avatar teaflavored avatar wojtekmaj avatar znarf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prop-types's Issues

childrenOfType incompatible with projects using react-hot-loader

childrenOfType is currently incompatible with projects using react-hot-loader because of this line:

https://github.com/airbnb/prop-types/blob/master/src/childrenOfType.js#L8

According to the react-hot-loader docs, because React Hot Loader creates proxied versions of your components, comparing reference types of elements won't work. It looks like they provide an areComponentsEqual helper that checks for that (more details here), but I'm not sure if there's a good way to integrate with this.

It looks like there is an open issue on react-hot-loader about this -- curious if you guys have any ideas for a solution or workaround: gaearon/react-hot-loader#304

[feature request] forbidInnerExtraProps

This validator validates all inner props.
For example:

static propTypes = forbidExtraProps({
  firstLevelProp: PropTypes.shape({
    secondLevelProp: PropTypes.string,
  }),
});

<ThisComponent
  qwe // will warn
  firstLevelProp={{
    rty: true, // won't warn
  }}
/>

But

static propTypes = forbidInnerExtraProps({
  firstLevelProp: PropTypes.shape({
    secondLevelProp: PropTypes.string,
  }),
});

<ThisComponent
  qwe // will warn
  firstLevelProp={{
    rty: true, // will warn too
  }}
/>

TypeError: Object.entries is not a function (version 2.4)

TypeError: Object.entries is not a function
    at propsThunkify (C:\dev\source\test\main\src\node_modules\airbnb-prop-types\build\between.js:106:17)
    at betweenValidator (C:\dev\source\test\main\src\node_modules\airbnb-prop-types\build\between.js:144:20)
    at Object.<anonymous> (C:\dev\source\test\main\src\node_modules\airbnb-prop-types\build\sequenceOf.js:41:101)
    at Module._compile (module.js:541:32)
    at Object.require.extensions.(anonymous function) [as .js] (C:\dev\source\test\main\src\node_modules\node-jsx\index.js:29:12)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)

Encountered this bug while trying to use react-dates.
Had to force usage of version 2.2.0.

SyntaxError: Unexpected identifier on `forbidExtraProps` from `prop-types-exact`

Hello, good work with this repo.
I'm getting this error when testing with Jest, also the same error ocurr with TypeScript.

.../airbnb-prop-types/src/forbidExtraProps.js:1 (function (exports, require, module, __filename, __dirname) { import forbidExtraProps from 'prop-types-exact'; ^^^^^^^^^^^^^^^^ SyntaxError: Unexpected identifier

I'm using Babel 7.

Check for children of fragments in `childrenOfType` validator

I have a component with a sub-component API and I want to validate that the children of the component are a part of that sub-component API. The childrenOfType validator lets me do this (thanks!), but I have discovered an edge case that could be solved with slight modification to the existing validator. The edge case is when a fragment is used to wrap the children. For example, consider the following sub-component API + component prop-types spec:

// Sub-component API
Component.A = A;
Component.B = B;

Component.propTypes = {
  children: childrenOfType(Component.A, Component.B),
};

Now, if I am conditionally rendering the children of the component and a case where multiple child elements are the resulting expression I need to wrap those with a fragment so that it is valid JSX. This causes childrenOfType to err.

<Component>
  {someCondition ? (
    <>
      <Component.A>Some content</Component.A>
      <Component.B>Some more content</Component.B>
    </> 
  ) : (
    <Component.A>
      Some other content
    </Component.A>
  )}
</Component>

I do realize that the above could be solved by writing the conditional differently, however, I do think that it seems reasonable for the childrenOfType validator to recognize a fragment as a non-element and to forward its checking of the children to the fragment. Thoughts?

mutually exclusively require prop

I have a component and it can take a prop of 'src' or children, but never both. I was unable to find a proptype supplied in this library to cover this.

@ljharb was helping me compose a prop-type for this and while it does seem to disallow the other prop if one is already provided, it doesn't also require that one exist.

here is the proposed prop-type:

static propTypes = {
src: disallowedIf(string, "children", any.isRequired),
children: disallowedIf(
oneOfType([arrayOf(node), node]),
"src",
any.isRequired
)
};

I am happy to contribute a solution for a mutulallyExclusivelyRequired or something similar if needs be.

Thanks!

`componentWithName` fails when used with `childrenOf` and `forwardRef`

Consider the following:

const Foo = () => {
 // ...
}

Foo.displayName = 'Foo';

const Bar = () => {
  // ...
}

Bar.propTypes = {
  children: childrenOf(componentWithName("Foo"))
}

When used like this, childrenOf and componentWithName work as expected. However, if we wrap Foo in a forwardRef wrapper like so:

const Foo = React.forwardRef(() => {
 // ...
});

Foo.displayName = 'Foo';

const Bar = () => {
  // ...
}

Bar.propTypes = {
  children: childrenOf(componentWithName("Foo"))
}

Then we receive the following warning:

Warning: Failed prop type: `Bar.children` only accepts components named Foo, got null

I believe this is down to this helper function only checking that the component is a function, when it becomes an object after it's wrapped in the forwardRef. Would there be any possibility of checking that the component type is a function or an object?

if (typeof Component === 'function') {

Generating documentation

Hi,

amazing upgrade to PropTypes.

I was wondering what do you use to generate documentation.
I guess possible react-docgen version with custom handlers but that might not be enough?

Thanks in advance
Alex

How to use

Hi,
a few lines in readme on how to use this would be nice.

Would also like to know how does this play with the newly isolated prop-types package.

`forbidExtraProps` incompatible with eslint-plugin-react propType rules?

Using forbidExtraProps like so prevents ESLint from catching any propType violations from eslint-plugin-react (sort-prop-types, forbid-prop-type, etc.):

class AwesomeComponent extends React.Component {
  static propTypes = forbidExtraProps({
    stringThing: PropTypes.string.isRequired,
    boolThing: PropTypes.bool.isRequired,
  });
...
}

Removing forbidExtraProps in the example above allows ESLint to recognize a sort-prop-type violation.

I've tried different syntaxes for defining propTypes, but they all prevent ESLint from seeing these violations. It looks as if the wonderful people at Airbnb are using forbidExtraProps and at least some of these eslint-plugin-react propType rules together - would you please let me know how you've gotten these libraries to work together when you have a moment? Thanks very much for your time!

`or` with classic `oneOf` losing prettiness of the warning message

When I call this

PropTypes.checkPropTypes({
  theme: AirbnbPropTypes.or([
    PropTypes.oneOf(['normal', 'pseudo']), // basic set of values, comes from library
    PropTypes.oneOf(['my-custom']) // local addition to base component
  ])
}, {theme: 'abnormal'}, 'theme', 'Button');

... and I see this: (actual):

Warning: Failed theme type: Button: invalid value supplied to theme.

But want to see this (expected):

Warning: Failed theme type: Invalid theme `theme` of value `abnormal` supplied to `Button`,
expected one of ["normal","pseudo"] or one of ["my-custom"].

Or even (ideal):

> PropTypes.checkPropTypes({theme: PropTypes.oneOf(['normal', 'pseudo', 'my-custom'])}, {theme: 'abnormal'}, 'theme', 'Button')
Warning: Failed theme type: Invalid theme `theme` of value `abnormal` supplied to `Button`,
expected one of ["normal","pseudo","my-custom"].

Versions:

  • prop-types: "15.6.0"
  • airbnb-prop-types: "2.8.1"

forbidExtraProps seems to have no effect

All the other prop types checks we use both from airbnb and elsewhere seem to work as expected, but forbidExtraProps has no effect no matter where we try it or what we pass it.

We're using [email protected] with [email protected].

Any thoughts? Is it broken? Surely we can't be the only ones?

We do not use Use of airbnb-js-shims, but after reviewing the shims, all functions are already supported in our environment without shimming.

SyntaxError Unexpected end of script at `t.getComponentName(airbnb-prop-types/src/helpers/getComponentName)`

We got this error from airbnb proptypes... haven't faced such issue before.

it throws an error on line

export default function getComponentName(Component) {

For more detail can check here for issue that we catch on our sentry instance: https://umai.sentry.io/share/issue/23296973e27047f28f20447e8519fcc4/

Versions:

├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]

SyntaxError: Unexpected identifier on `forbidExtraProps` from `prop-types-exact`

Good work with this repo.
I'm getting this error when testing with Jest, also the same error occurs with TypeScript.

.../node_modules/airbnb-prop-types/src/forbidExtraProps.js:1
(function (exports, require, module, __filename, __dirname) { import forbidExtraProps from 'prop-types-exact';
                                                                     ^^^^^^^^^^^^^^^^
....
SyntaxError: Unexpected identifier
....

I'm using Babel 7.

childrenHavePropXorChildren will throw error for falsey children

Looking at the src for https://github.com/airbnb/prop-types/blob/master/src/childrenHavePropXorChildren.js, this following code will throw an error for falsey children.

React.Children.forEach(children, (child) => {
    if (child.props[prop]) {
        propCount += 1;
    }
    if (React.Children.count(child.props.children)) {
        grandchildrenCount += 1;
    }
});

I don't know if this is the intended behavior, but what do you guys think about adding an option for childrenHavePropXorChildren to skip over falsey children. If this sounds like something acceptable, then I can create a PR for it.

Deprecated PropType

A new PropType for denoting a prop as deprecated would be useful in slowly migrating components. It would simply call console.warn in non-production and pass through the original PropType.

Something like the following:

import { deprecated } from 'airbnb-prop-types';

const propTypes = {
  title: deprecated(PropTypes.string, 'Please use "children" instead.'),
  children: PropTypes.node,
};

Shortcut method for mutuallyExclusiveTrueProps?

Currently, if you want to use mutuallyExclusiveTrueProps, you need to do something like this:

const fooProp = mutuallyExclusiveTrueProps('foo', 'bar', 'baz');

Foo.propTypes = {
  foo: fooProp,
  bar: barProp,
  baz: bazProp,
};

I wonder if it would be useful to be able to do something more like:

Foo.propTypes = {
  ...mutuallyExclusiveTrueProps('foo', 'bar', 'baz'),
};

And, if you wanted to also have this generate the defaultProps for you:

Foo.propTypes = {
  ...mutuallyExclusiveTrueProps('foo', 'bar', 'baz').propTypes,
};
Foo.defaultProps = {
  ...mutuallyExclusiveTrueProps('foo', 'bar', 'baz').defaultProps,
};

or, obviously:

const fooProps = mutuallyExclusiveTrueProps('foo', 'bar', 'baz');
Foo.propTypes = {
  ...fooProps.propTypes,
};
Foo.defaultProps = {
  ...fooProps.defaultProps,
};

The main drawback to this that I think of right now is that it might not work so well with some of the React lint rules.

I'm not sure what this method should be named, or perhaps if we add propTypes and defaultProps, we could just attach those to the return value of the current method as a convenience.

Or Tests seem to be wrong

The or tests seem to repeat the double required case.

    it('works when outer and inner are optional', () => {
      assertPasses(or([bool.isRequired, explicitNull()]), (<div a />), 'a');
      ...
    });

    it('works when outer is optional, inner is required', () => {
      assertPasses(or([bool.isRequired, explicitNull().isRequired]), (<div a />), 'a');
      ...
    });

    it('works when outer is required, inner is optional', () => {
      assertPasses(or([bool.isRequired, explicitNull()]).isRequired, (<div a />), 'a');
      ...
    });

    it('works when outer is required, inner is required', () => {
      assertPasses(or([bool.isRequired, explicitNull().isRequired]).isRequired, (<div a />), 'a');
      ...
    });

The above should instead be the following

    it('works when outer and inner are optional', () => {
      assertPasses(or([bool, explicitNull()]), (<div a />), 'a');
      ...
    });

    it('works when outer is optional, inner is required', () => {
      assertPasses(or([bool, explicitNull().isRequired]), (<div a />), 'a');
      ...
    });

    it('works when outer is required, inner is optional', () => {
      assertPasses(or([bool.isRequired, explicitNull()]), (<div a />), 'a');
      ...
    });

    it('works when outer is required, inner is required', () => {
      assertPasses(or([bool.isRequired, explicitNull().isRequired]).isRequired, (<div a />), 'a');
      ...
    });

Dependency of `object.entries`?

Can't build in webpack, seeing the following error:

TypeError: Object.entries is not a function
    at propsThunkify (/Users/siqitian/src/app-renderer/node_modules/airbnb-prop-types/build/between.js:106:17)
    at betweenValidator (/Users/siqitian/src/app-renderer/node_modules/airbnb-prop-types/build/between.js:144:20)
    at Object.<anonymous> (/Users/siqitian/src/app-renderer/node_modules/airbnb-prop-types/build/sequenceOf.js:41:101)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
/Users/siqitian/src/app-renderer/dev-server/dev-server.js:81
      throw (e);
      ^

Shall we include the shim of object.entries?

`explicitNull` does not work when part of `PropTypes.oneOfType`

Things that work as expected:
foo: explicitNull().isRequired breaks for anything that is not foo={null}, including foo={undefined}.
foo: PropTypes.oneOfType([explicitNull()]).isRequired breaks on foo="foo"
foo: PropTypes.oneOfType([explicitNull().isRequired]) breaks on foo="foo"

Things that do not work as expected:
foo: PropTypes.oneOfType([explicitNull()]).isRequired breaks on foo={null}
foo: PropTypes.oneOfType([explicitNull().isRequired]) passes on foo={undefined}

React 17 peer support

NPM warning [email protected] requires a peer of react@^0.14 || ^15.0.0 || ^16.0.0-alpha but none is installed. You must install peer dependencies yourself. with React 17.

Please release support for the peer dependency.

Question: Using sequenceOf?

I am attempting to use sequenceOf, but I don't seem to be able to get it correct. An example of my use

import PropTypes from 'prop-types';
import AirbnbPropTypes from 'airbnb-prop-types';
...
  static propTypes = {
    step: AirbnbPropTypes.sequenceOf({ validator: PropTypes.number, min: 1, max: 5 }),
  };

  static defaultProps = {
    step: 1,
  };

Whatever integer value of step I supply as a prop to this component, I get this warning:

warning.js?85a7:36 Warning: Failed prop type: Invalid prop 'step' of type number supplied to 'Picker', expected 'array'.

If I supply a string value, then I get

warning.js?85a7:36 Warning: Failed prop type: Invalid prop 'step' of type 'string' supplied to 'Picker', expected 'array'.

I'm clearly not understanding something? I'm looking for that "Aha!" moment. :)

`mutuallyExclusiveProps` is unintuitive / poorly documented

mutuallyExclusiveProps() only checks that at least one exclusive prop is provided. Otherwise it throws with at least one prop that is mutually exclusive with this propType is required. However, two exclusive props are required for mutuallyExclusiveProps() to do anything, since the current propName is not considered an exclusive prop.

// All equivalent
foo: mutuallyExclusiveProps(validator, 'foo')
foo: mutuallyExclusiveProps(validator, 'bar')
foo: mutuallyExclusiveProps(validator, 'foo').isRequired
foo: mutuallyExclusiveProps(validator, 'bar').isRequired
foo: validator

The behavior of mutuallyExclusiveProps().isRequired is unclear. The only requirement is that

it('fails when required, and one of the exclusive props is null/undefined')

and this doesn't describe the current behavior of .isRequired. Currently, if the current propName is not listed as an exclusive prop, then mutuallyExclusiveProps() behaves the exact same as mutuallyExclusiveProps().isRequired. If the current propName is included as an exclusive prop, then the only difference is that propName={null/undefined} is additionally considered as a set prop.

This seems strange because of the following scenario:

Component.propTypes = {
  foo: mutuallyExclusiveProps(any, 'foo', 'bar').isRequired
}

<Component bar /> // passes
<Component foo={null} bar /> // fails
<Component foo={undefined} bar /> // fails

Children of children / recursive validation

I want to validate the children of an element that's passed as children.

For example:

<x><y/></x>

Where y is wrapped with injectIntl and, so I want to check in x that y is either of type "A" or type "B", but because it's wrapped, I need to go one level deep.

Is there a way to do this with these proptypes?

childrenOfType doesn't help because it can only check if it's of type injectIntl.

pass-through prop-type validators

since the prop-types package is a dependency, I'd love to see this package with all the original prop-type validators as well.

that way I can import PropTypes from 'airbnb-prop-types' and get all the things.

or is there a way to achieve this already? I'm just not aware of it?

Invalid isRequired could likely use a better error message

I have this as my code:

LoanForm.propTypes = {
  handleSubmit: PropTypes.func.isRequired,
  loan: PropTypes.object.isRequred
};

and received the following error message:

Failed prop type: LoanFormInner: prop type 'loan' is invalid; it must be a function, usually from the 'prop-type' package, but received 'undefined'.

The subtlety is that in loan: PropTypes.object.isRequred, isRequired is spelled wrong. It didn't take me too long to discover the spelling error but the error message didn't really help.

I am curious if you all would be opened to making the error message a little more clear.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.