How to use the shape function from prop-types

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

107
108
109
110
111
112
113
114
115

// You can chain any of the above with `isRequired` to make sure a warning
// is shown if the prop isn't provided.

// An object taking on a particular shape
optionalObjectWithShape: PropTypes.shape({
  optionalProperty: PropTypes.string,
  requiredProperty: PropTypes.number.isRequired
}),
fork icon388
star icon0
watch icon3

+ 7 other calls in file

70
71
72
73
74
75
76
77
78
79
    message: PropTypes.string,
    items: PropTypes.arrayOf(PropTypes.shape({
        posterShape: PropTypes.string
    })),
    itemComponent: PropTypes.elementType,
    deepLinks: PropTypes.shape({
        discover: PropTypes.string,
        library: PropTypes.string
    })
};
fork icon129
star icon506
watch icon31

+ 3 other calls in file

32
33
34
35
36
37
38
39
40
41
        </Styled.ThemeProvider>
    );
};

module.exports.propTypes = {
    middleEnd: T.shape({
        store: T.object.isRequired
    }).isRequired,
    theme: T.object,
    Router: T.elementType
fork icon7
star icon35
watch icon13

+ 3 other calls in file

77
78
79
80
81
82
83
84
85
86

/**
 * 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.
     */
    uri: PropTypes.string,
fork icon87
star icon0
watch icon76

+ 3 other calls in file

12
13
14
15
16
17
18
19
20
21
class FileUpload extends React.Component {
  static propTypes = {
    allowedFileTypes: PropTypes.array,
    elementRef: PropTypes.func,
    imageUrl: PropTypes.string,
    imageValidation: PropTypes.shape({
      exactHeight: PropTypes.number,
      exactWidth: PropTypes.number,
      maxHeight: PropTypes.number,
      maxWidth: PropTypes.number,
fork icon61
star icon78
watch icon23

44
45
46
47
48
49
50
51
52
53
		hasOutput: PropTypes.bool,
		output: PropTypes.array,
		hasError: PropTypes.bool,
		error: PropTypes.string
	}),
	xdebug: PropTypes.shape({
		status: PropTypes.string
	}),
	container: PropTypes.func.isRequired
};
fork icon7
star icon42
watch icon4

38
39
40
41
42
43
44
45
46
47
    zh: PropTypes.string.isRequired,
    en: PropTypes.string.isRequired
  })
])

const formType = PropTypes.shape({
  title: stringType,
  formItems: PropTypes.arrayOf(PropTypes.shape({
    label: stringType,
    mdTitle: PropTypes.string,
fork icon0
star icon4
watch icon2

+ 5 other calls in file

9
10
11
12
13
14
15
16
17
18
19
20
21


'use strict';


const PropTypes = require('prop-types');


const ImageURISourcePropType = PropTypes.shape({
  uri: PropTypes.string,
  bundle: PropTypes.string,
  method: PropTypes.string,
  headers: PropTypes.objectOf(PropTypes.string),
fork icon5
star icon3
watch icon0

849
850
851
852
853
854
855
856
857
858
859
}


if (process.env.NODE_ENV !== 'production') {
  FileViewer.propTypes = {
    path: PropTypes.string.isRequired,
    details: PropTypes.shape({
      contentType: PropTypes.string.isRequired,
      highlights: PropTypes.arrayOf(PropTypes.string),
      // code
      uri: PropTypes.string,
fork icon0
star icon1
watch icon0

+ 2 other calls in file

245
246
247
248
249
250
251
252
253
254
size: PropTypes.number,
level: PropTypes.oneOf(['L', 'M', 'Q', 'H']),
bgColor: PropTypes.string,
fgColor: PropTypes.string,
includeMargin: PropTypes.bool,
imageSettings: PropTypes.shape({
    src: PropTypes.string.isRequired,
    height: PropTypes.number.isRequired,
    width: PropTypes.number.isRequired,
    excavate: PropTypes.bool,
fork icon0
star icon0
watch icon1

+ 8 other calls in file

186
187
188
189
190
191
192
193
194
195
commentee: PropTypes.string,
intl: intlShape.isRequired,
objectId: PropTypes.number.isRequired,
objectTitle: PropTypes.string,
objectType: PropTypes.oneOf([0, 1, 2]).isRequired,
user: PropTypes.shape({
    id: PropTypes.number,
    banned: PropTypes.bool,
    username: PropTypes.string,
    token: PropTypes.string,
fork icon0
star icon0
watch icon1

+ 3 other calls in file

987
988
989
990
991
992
993
994
995
996
    email: PropTypes.string,
    classroomId: PropTypes.string
}),
userOwnsProject: PropTypes.bool,
userPresent: PropTypes.bool,
visibilityInfo: PropTypes.shape({
    censored: PropTypes.bool,
    censoredByAdmin: PropTypes.bool,
    censoredByCommunity: PropTypes.bool,
    message: PropTypes.string,
fork icon0
star icon0
watch icon1

588
589
590
591
592
593
594
595
596
597
        listKey: React$PropType$Primitive<string>,
        cellKey: React$PropType$Primitive<string>,
      |},
    |},
  |} = {
virtualizedCell: PropTypes.shape({
  cellKey: PropTypes.string,
}),
virtualizedList: PropTypes.shape({
  getScrollMetrics: PropTypes.func,
fork icon0
star icon0
watch icon1

+ 13 other calls in file

18
19
20
21
22
23
24
  theme: PropTypes.oneOf(['dark', 'light']),
  dnt: PropTypes.string,
  hideConversation: PropTypes.oneOf([undefined, 'on']),
};


module.exports = PropTypes.shape(CONFIGURATION_TYPE);
fork icon0
star icon0
watch icon1

+ 7 other calls in file

85
86
87
88
89
90
91
92
93
94
    return [];
  }
}

// Always returns an object with this shape:
// PropTypes.shape(
//   { values: PropTypes.arrayOf( PropTypes.string ).isRequired
//   , propertyVerbs: PropTypes.arrayOf( PropTypes.string).isRequired
//   })
findValues( propId )
fork icon0
star icon0
watch icon1

+ 8 other calls in file

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218


  return ReactPageShell;
}(React.Component);


ReactPageShell.propTypes = {
  meta: PropTypes.shape({
    title: PropTypes.string.isRequired,
    description: PropTypes.string.isRequired,
    contentType: PropTypes.string,
    pathname: PropTypes.string,
fork icon0
star icon0
watch icon0

1
2
3
4
5
6
7
8
9
10
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,
    })),
    PropTypes.string,
fork icon0
star icon0
watch icon2