reactnode prop types

Solutions on MaxInterview for reactnode prop types by the best coders in the world

showing results for - "reactnode prop types"
Brenton
05 Jul 2019
1import PropTypes from 'prop-types';
2
3MyComponent.propTypes = {
4  // You can declare that a prop is a specific JS type. By default, these
5  // are all optional.
6  optionalArray: PropTypes.array,
7  optionalBool: PropTypes.bool,
8  optionalFunc: PropTypes.func,
9  optionalNumber: PropTypes.number,
10  optionalObject: PropTypes.object,
11  optionalString: PropTypes.string,
12  optionalSymbol: PropTypes.symbol,
13
14  // Anything that can be rendered: numbers, strings, elements or an array
15  // (or fragment) containing these types.
16  optionalNode: PropTypes.node,
17
18  // A React element.
19  optionalElement: PropTypes.element,
20
21  // A React element type (ie. MyComponent).
22  optionalElementType: PropTypes.elementType,
23
24  // You can also declare that a prop is an instance of a class. This uses
25  // JS's instanceof operator.
26  optionalMessage: PropTypes.instanceOf(Message),
27
28  // You can ensure that your prop is limited to specific values by treating
29  // it as an enum.
30  optionalEnum: PropTypes.oneOf(['News', 'Photos']),
31
32  // An object that could be one of many types
33  optionalUnion: PropTypes.oneOfType([
34    PropTypes.string,
35    PropTypes.number,
36    PropTypes.instanceOf(Message)
37  ]),
38
39  // An array of a certain type
40  optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
41
42  // An object with property values of a certain type
43  optionalObjectOf: PropTypes.objectOf(PropTypes.number),
44
45  // An object taking on a particular shape
46  optionalObjectWithShape: PropTypes.shape({
47    color: PropTypes.string,
48    fontSize: PropTypes.number
49  }),
50
51  // An object with warnings on extra properties
52  optionalObjectWithStrictShape: PropTypes.exact({
53    name: PropTypes.string,
54    quantity: PropTypes.number
55  }),   
56
57  // You can chain any of the above with `isRequired` to make sure a warning
58  // is shown if the prop isn't provided.
59  requiredFunc: PropTypes.func.isRequired,
60
61  // A required value of any data type
62  requiredAny: PropTypes.any.isRequired,
63
64  // You can also specify a custom validator. It should return an Error
65  // object if the validation fails. Don't `console.warn` or throw, as this
66  // won't work inside `oneOfType`.
67  customProp: function(props, propName, componentName) {
68    if (!/matchme/.test(props[propName])) {
69      return new Error(
70        'Invalid prop `' + propName + '` supplied to' +
71        ' `' + componentName + '`. Validation failed.'
72      );
73    }
74  },
75
76  // You can also supply a custom validator to `arrayOf` and `objectOf`.
77  // It should return an Error object if the validation fails. The validator
78  // will be called for each key in the array or object. The first two
79  // arguments of the validator are the array or object itself, and the
80  // current item's key.
81  customArrayProp: PropTypes.arrayOf(function(propValue, key, componentName, location, propFullName) {
82    if (!/matchme/.test(propValue[key])) {
83      return new Error(
84        'Invalid prop `' + propFullName + '` supplied to' +
85        ' `' + componentName + '`. Validation failed.'
86      );
87    }
88  })
89};
queries leading to this page
react proptypes object with keysprops type reactfor boolean types proptypeswhy use prop typesproptype for functionreact native proptypesproptypes anyreact prop types 5creact ts prop types with routerreact native proptypes functionset prop types in reactprop types one ofreact proptypeprop types usesreact proptypes in functional componentreactnode prop typesprop types exactproptypes javascriptpredefined proptypes in reactprop typesreact define proptypes in classreact proptypes descriptionproptypes nodehow prop types work in reacthow to import proptypes in reactstatic proptypes react jsuse of proptypes in reactimport proptypes from 27prop types 27 typescripthow to use proptypes in reactprop expexted typesproptypes react elementprop types jsreact prop typesproptypes reactjsreact native proptypes documentationintroduce proptypes for better validations for usages of componentsreact js prop typesprop types react how to useproptypes for a react componentproptypes or key prop types objectreactjs prop typeswhat are react prop typesnpm prop typesreact proptypes object with keysimport proptypes from 27prop typespropstypes in reactdo you need prop types with typescriptreact prop typesprop types react npmcomponent should include prop types which require the name prop to be of type stringreact prop types and jsdocproptypes require 1 ofproptype elementreact prop type nodeprop types npmprop typereact state proptypesproptypes reactshould i use proptypes with typescriptreact class proptypestypes of propsproptypes functionprops types in reactjsnew type for proptypes typescriptwrite types for propsproptypes react numberprototype reactdo i need prop types if i use typescriptproptypes react typescripttypescript react prop interfaceproptype react node 27proptypes in reactproptypes stringjsx element define props typeproptypes in reactreact 2fprop types ruleprop type for componenttypescript doc 40see propreact proptypes npmreact proptypes of anyhow to add prop types in reactproptypes apitypes in react propsreact proptype array prop types reactonetypeof proptypes in reactreact prop types oneoftypeimport proptypes from 27prop types 27 3bhow to set prop types in typescript reactjs proptypesset prop types reactprop types onwhat is proptype in jsreact proptypes object ofreact javascript prop typesproptypes import reactreactjs proptypesproptypes in class components in reactprop types how to use in typescriptdefine prop typesproptype node reactprop types oneoftypedoes prop types come with reactprop types packagenpm i proptypesprop types npmprop types react npmreact prop typesinstall prop typesimport node from 22prop types 22 3bproptype reactis prop types come in reactreact proptypesreact proptypes typescriptnpm prop typesnpm proptypesproptypes node typeproptypes npmreact component prop typereact proptypetypes of props in react jsprop types typescriptinstall react prop typesprop typesproptypes types functionset prop types tsxreact proptypes fcomponentprop types react examplenpm prop types 27prop types 4015 7 2 2fdeno 2fprop types jsproptypes in react typescripthow to require theh right data type in reactproptype for react componentspecific value for prop typesreact prop typesproptypes react nodeimport 7b proptypes 7d from 27prop types 27 3bprop types in react nativereact proptypes styleprop types react nativeadd proptypesproptypes object javascriptprop types 4015 7 2 2fprop types min jsproptypes objectproptypes node exampleare proptypes node same as react reactnodecustom prop typesproptypes in typescriptprop types in reactreact proptypes for objectreact create props typeproptype for react nodejavascript proptypestypescript react proptypesprops typesprop types developmentprop types reactwhat are proptypes in reactprop type reactinstall prop typeshow to install proptypes in reactprop types importreact js props typesprop types in react jshow to install prop types reactjsreactnode prop types