0.5.1 • Published 9 years ago
react-results-proptypes v0.5.1
Results PropTypes for React
$ npm install react-results-proptypesimport { unionOf, maybeOf } from 'react-results-proptypes';
// this would be declared somewhere else in the app and imported
const MyUnion = Union({ A: null, B: null, C: null });
const MyComponent = React.createClass({
  propTypes: {
    maybeAString: maybeOf(React.PropTypes.string),
    thingFromMyUnion: unionOf(MyUnion, {
      A: React.PropTypes.string,
      B: React.PropTypes.number,
      C: null,
    }),
  },
  ...
});The component above would pass checks if:
maybeAStringwereMaybe.None()orMaybe.Some('string')thingFromMyUnionwere any ofMyUnion.A('blah'),MyUnion.B(42),MyUnion.C()