dillon1000/react

Commit

ReactPropTypes: add `oneOfType` to support union types

Summary:
e.g.

  propTypes: {
    foo: React.PropTypes.oneOfType([
      React.PropTypes.string,
      React.PropTypes.number
    ]);
  }

to do this, I exposed a `.weak` chainable validator that returns instead of throws, e.g.

  React.PropTypes.string.isRequired.weak
  React.PropTypes.string.weak

which returns true or false. Technically, `React.PropTypes.string.weak.isRequired` also exists, but `oneOfType` will never call it. Might be useful to people creating custom validators though.
Browse files
Changed paths2 files
First-parent comparison
M src/core/ReactPropTypes.js ModifiedM src/core/__tests__/ReactPropTypes-test.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…