How to use the oneOfType function from prop-types

Find comprehensive JavaScript prop-types.oneOfType code examples handpicked from public code repositorys.

94
95
96
97
98
99
100
101
102
103
// You can ensure that your prop is limited to specific values by treating
// it as an enum.
optionalEnum: PropTypes.oneOf(['News', 'Photos']),

// An object that could be one of many types
optionalUnion: PropTypes.oneOfType([
  PropTypes.string,
  PropTypes.number,
  PropTypes.instanceOf(Message)
]),
fork icon388
star icon0
watch icon59

76
77
78
79
80
81
82
83
84
85
),

/**
 * Loads static html or a uri (with optional headers) in the WebView.
 */
source: PropTypes.oneOfType([
  PropTypes.shape({
    /*
     * The URI to load in the WebView. Can be a local or remote file.
     */
fork icon87
star icon0
watch icon76

1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
      onClose: handleClose
    }))]
  });
});
process.env.NODE_ENV !== "production" ? Menu.propTypes = /*#__PURE__*/_extends({}, rootMenuPropTypes, uncontrolledMenuPropTypes, {
  menuButton: propTypes.oneOfType([propTypes.element, propTypes.func]).isRequired
}) : void 0;


var _excluded$6 = ["aria-label", "className", "disabled", "direction", "label", "openTrigger", "onMenuChange", "isHovering", "instanceRef", "itemRef", "captureFocus", "repositionFlag", "itemProps"],
  _excluded2$2 = ["ref", "className"];
fork icon48
star icon883
watch icon6

+ 5 other calls in file

30
31
32
33
34
35
36
37
38
39
    ))
    cb && cb()
  })
}

const stringType = PropTypes.oneOfType([
  PropTypes.string.isRequired,
  PropTypes.shape({
    zh: PropTypes.string.isRequired,
    en: PropTypes.string.isRequired
fork icon0
star icon4
watch icon2

26
27
28
29
30
31
32
33
34
35
36
  width: PropTypes.number,
  height: PropTypes.number,
  scale: PropTypes.number,
});


const ImageSourcePropType = PropTypes.oneOfType([
  ImageURISourcePropType,
  // Opaque type returned by require('./image.jpg')
  PropTypes.number,
  // Multiple sources
fork icon5
star icon3
watch icon0

1
2
3
4
5
6
7
8
9
10
11
const PropTypes = require('prop-types');
const singleInstance = require('../single-instance');


module.exports = class Link extends React.PureComponent {
  static propTypes = {
    to: PropTypes.oneOfType([
      PropTypes.string.isRequired,
      PropTypes.shape({
        name: PropTypes.string.isRequired,
        params: PropTypes.object,
fork icon1
star icon2
watch icon2

+ 4 other calls in file

17
18
19
20
21
22
23
24
25
26
    exact: PropTypes.bool,
    replace: PropTypes.bool,
    scrollFirst: PropTypes.bool,
    children: PropTypes.node,
    onMove: PropTypes.func,
    scrollTo: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string,
    ]),
};
fork icon0
star icon2
watch icon1

822
823
824
825
826
827
828
829
830
831
  value: PropTypes.string.isRequired,
  onCaretPositionChange: PropTypes.func.isRequired,
  containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
    current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
  })]),
  children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
};
var styled = createDefaultStyle({
  position: 'relative',
  boxSizing: 'border-box',
fork icon0
star icon0
watch icon3

+ 31 other calls in file

897
898
899
900
901
902
903
904
905
906
907
}


Preview.propTypes = {
    assetHost: PropTypes.string.isRequired,
    // If there's no author, this will be false`
    authorId: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
    authorThumbnailUrl: PropTypes.string,
    // If there's no author, this will be false`
    authorUsername: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
    backpackHost: PropTypes.string,
fork icon0
star icon0
watch icon1

580
581
582
583
584
585
586
587
588
589
590
591
  }
}


ObjectBlock.propTypes = {
  viewOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  active: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  editable: PropTypes.oneOfType([PropTypes.bool, PropTypes.number])
};


ObjectBlock.defaultProps = {
fork icon0
star icon0
watch icon4

+ 2 other calls in file

195
196
197
198
199
200
201
202
203
204
      </div>
    );
  }
}
Canvas.propTypes = {
  visible: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  viewOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  bottomPagination: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  getCanvasRef: PropTypes.func,
  getContainerRef: PropTypes.func,
fork icon0
star icon0
watch icon4

+ 3 other calls in file

258
259
260
261
262
263
264
265
266
267
  textAlign: PropTypes.oneOf(["left", "center", "justify", "right"]),
  underline: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  bold: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  italic: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  lineHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  wordSpacing: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  letterSpacing: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  fillColor: PropTypes.string
};

fork icon0
star icon0
watch icon4

+ 5 other calls in file

476
477
478
479
480
481
482
483
484
485
outline: PropTypes.bool,
rounded: PropTypes.bool,
circle: PropTypes.bool,
floating: PropTypes.bool,
flat: PropTypes.bool,
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
onClick: PropTypes.func,
size: PropTypes.string,
social: PropTypes.string,
children: PropTypes.node,
fork icon0
star icon0
watch icon1

+ 289 other calls in file

865
866
867
868
869
870
871
872
873
874
    }]);
    return HelmetWrapper;
}(React.Component), _class.propTypes = {
    base: PropTypes.object,
    bodyAttributes: PropTypes.object,
    children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
    defaultTitle: PropTypes.string,
    defer: PropTypes.bool,
    encodeSpecialCharacters: PropTypes.bool,
    htmlAttributes: PropTypes.object,
fork icon0
star icon0
watch icon1

+ 3 other calls in file

162
163
164
165
166
167
168
169
170
171
172
173
};


MapProvider.propTypes = {
  width: PropTypes.number,
  height: PropTypes.number,
  projection: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
  projectionConfig: PropTypes.object
};


var ComposableMap = function ComposableMap(_ref) {
fork icon0
star icon0
watch icon0

+ 4 other calls in file

16
17
18
19
20
21
22
23
24
25
26
RadioBlockGroup.defaultProps = {
  styles: {}
}


RadioBlockGroup.propTypes = {
  styles: PropTypes.oneOfType([
    PropTypes.array,
    PropTypes.objectOf(CustomPropTypes.style)
  ])
}
fork icon0
star icon0
watch icon0

0
1
2
3
4
5
6
7
8
9
const PropTypes = require('prop-types');
const exact = require('prop-types-exact');

const link = module.exports.link = exact({
  title: PropTypes.string.isRequired,
  author: PropTypes.oneOfType([
    PropTypes.shape(exact({
      name: PropTypes.string.isRequired,
      url: PropTypes.string,
    })),
fork icon0
star icon0
watch icon2

+ 5 other calls in file