How to use the func function from prop-types

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

prop-types.func is a function that can be used to check if a given prop is a valid function.

144
145
146
147
148
149
150
151
152
153
 * being highlighted by calling `highlightRow(sectionID, rowID)`. This
 * sets a boolean value of adjacentRowHighlighted in renderSeparator, allowing you
 * to control the separators above and below the highlighted row. The highlighted
 * state of a row can be reset by calling highlightRow(null).
 */
renderRow: PropTypes.func.isRequired,
/**
 * How many rows to render on initial component mount. Use this to make
 * it so that the first screen worth of data appears at one time instead of
 * over the course of multiple frames.
fork icon481
star icon0
watch icon231

+ 3 other calls in file

121
122
123
124
125
126
127
128
129
optionalObjectWithStrictShape: PropTypes.exact({
  optionalProperty: PropTypes.string,
  requiredProperty: PropTypes.number.isRequired
}),

requiredFunc: PropTypes.func.isRequired,

// A value of any data type
requiredAny: PropTypes.any.isRequired,
fork icon388
star icon0
watch icon59

How does prop-types.func work?

In React, prop-types.func is a type checker that is used to check whether the given prop is a function or not. If it is not a function, a warning will be logged in the console.

15
16
17
18
19
20
21
22
23
24
  updateOnEachImageLoad: PropTypes.bool,
  options: PropTypes.object,
  imagesLoadedOptions: PropTypes.object,
  elementType: PropTypes.string,
  onLayoutComplete: PropTypes.func,
  onRemoveComplete: PropTypes.func
};

var MasonryComponent = createReactClass({
  masonry: false,
fork icon145
star icon0
watch icon21

+ 3 other calls in file

24
25
26
27
28
29
30
31
32
33
  ratioHeight: PropTypes.number,
  ratioWidth: PropTypes.number
}),
maxFileSize: PropTypes.number,
onFileAdd: PropTypes.func.isRequired,
onFileRemove: PropTypes.func.isRequired,
onFileValidation: PropTypes.func,
style: PropTypes.object,
theme: themeShape,
uploadedFile: PropTypes.any
fork icon61
star icon78
watch icon23

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
import PropTypes from "prop-types";

function MyComponent(props) {
  // ...
}

MyComponent.propTypes = {
  onClick: PropTypes.func.isRequired,
  // ...
};

In this example, the onClick prop is defined as a required function using prop-types.func. This means that if the prop is provided, it must be a function or an error will be thrown.

7
8
9
10
11
12
13
14
15
const ShopifyConfigTypes = {
  apiKey: PropTypes.string.isRequired,
  host: PropTypes.string.isRequired,
  secret: PropTypes.string.isRequired,
  scope: PropTypes.arrayOf(PropTypes.string).isRequired,
  afterAuth: PropTypes.func.isRequired,
  shopStore: PropTypes.object,
  accessMode: PropTypes.oneOf(['offline', 'online'])
};
fork icon87
star icon0
watch icon1

1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
  captureFocus: propTypes.bool,
  menuItemFocus: /*#__PURE__*/propTypes.exact({
    position: /*#__PURE__*/propTypes.oneOfType([propTypes.string, propTypes.number]),
    alwaysUpdate: propTypes.bool
  }),
  onClose: propTypes.func
}) : void 0;


var _excluded$7 = ["aria-label", "captureFocus", "initialOpen", "menuButton", "instanceRef", "onMenuChange"];
var Menu = /*#__PURE__*/react.forwardRef(function Menu(_ref, externalRef) {
fork icon48
star icon883
watch icon6

+ 17 other calls in file

47
48
49
50
51
52
53
54
55
56
		error: PropTypes.string
	}),
	xdebug: PropTypes.shape({
		status: PropTypes.string
	}),
	container: PropTypes.func.isRequired
};

if (!checkProps(this.props, propTypes)) {
	return React.createElement(Loading, null);
fork icon7
star icon42
watch icon4

341
342
343
344
345
346
347
348
349
350
351
	})
}


createContributorNodes.propTypes = {
	contributors: PropTypes.array.isRequired,
	createNode: PropTypes.func.isRequired,
	createNodeId: PropTypes.func.isRequired,
	createContentDigest: PropTypes.func.isRequired
}

fork icon3
star icon12
watch icon3

+ 17 other calls in file

91
92
93
94
95
96
97
98
99
100
leftIcon: PropTypes.string,
leftIconColor: PropTypes.string,

backgroundColor: PropTypes.string,

onChangeText: PropTypes.func.isRequired,

isPasswordField: PropTypes.bool,

multilineInput: PropTypes.bool,
fork icon1
star icon2
watch icon1

109
110
111
112
113
114
115
116
117
118
119
120
          </AppContext.Consumer>;
}


Screen.propTypes =
  { externalroleinstance: PropTypes.string.isRequired
  , setMyRoleType: PropTypes.func.isRequired
  };


// Screen_ loads the component in the context of the role `externalroleinstance` that it receives on its props.
class Screen_ extends PerspectivesComponent
fork icon0
star icon0
watch icon1

754
755
756
757
758
759
760
761
762
763
const portalContainer = document.createElement('div');

class Component extends React.Component {
  static contextTypes = {
    foo: PropTypes.string.isRequired,
    getFoo: PropTypes.func.isRequired,
  };

  render() {
    return <div>{this.context.foo + '-' + this.context.getFoo()}</div>;
fork icon0
star icon0
watch icon1

+ 19 other calls in file

818
819
820
821
822
823
824
825
826
827
828


Highlighter.propTypes = {
  selectionStart: PropTypes.number,
  selectionEnd: PropTypes.number,
  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
fork icon0
star icon0
watch icon3

+ 3 other calls in file

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
ButtonToggle.defaultProps = defaultProps$16;


/**
 * DropdownContext
 * {
 *  toggle: PropTypes.func.isRequired,
 *  isOpen: PropTypes.bool.isRequired,
 *  direction: PropTypes.oneOf(['up', 'down', 'start', 'end']).isRequired,
 *  inNavbar: PropTypes.bool.isRequired,
 *  disabled: PropTypes.bool
fork icon0
star icon0
watch icon1

921
922
923
924
925
926
927
928
929
930
favedLoaded: PropTypes.bool,
fullScreen: PropTypes.bool,
getCommentById: PropTypes.func.isRequired,
getCuratedStudios: PropTypes.func.isRequired,
getFavedStatus: PropTypes.func.isRequired,
getLovedStatus: PropTypes.func.isRequired,
getMoreReplies: PropTypes.func.isRequired,
getOriginalInfo: PropTypes.func.isRequired,
getParentInfo: PropTypes.func.isRequired,
getProjectInfo: PropTypes.func.isRequired,
fork icon0
star icon0
watch icon1

+ 17 other calls in file

1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
  delay: PropTypes.oneOfType([PropTypes.shape({
    show: PropTypes.number,
    hide: PropTypes.number
  }), PropTypes.number]),
  onOpened: PropTypes.func,
  onClosed: PropTypes.func
};
Collapse.defaultProps = {
  isOpen: "",
  delay: DEFAULT_DELAYS,
fork icon0
star icon0
watch icon1

+ 99 other calls in file

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


class ButtonRecommendOption extends React.Component {
  static get propTypes() {
    return {
      onChange: PropTypes.func.isRequired,
      buttonRecommendation: PropTypes.array,
    };
  }

fork icon0
star icon0
watch icon1

+ 7 other calls in file

28
29
30
31
32
33
34
35
36
37
static get propTypes() {
  return Object.assign({}, CustomizationOptionUrlPropTypes, HostSettingsUrlPropTypes, {
    customizationOptions: ConfigurationType,
    hostSettings: PropTypes.object.isRequired,
    internalPreview: PropTypes.bool.isRequired,
    selectWidget: PropTypes.func.isRequired,
    selectedWidget: WidgetType,
    selectedWidgetQuery: PropTypes.string,
    setCustomizationOption: PropTypes.func.isRequired,
    setHostSetting: PropTypes.func.isRequired,
fork icon0
star icon0
watch icon1

+ 71 other calls in file

270
271
272
273
274
275
276
277
278
279
280
281
  }
}
RoleCard.contextType = PSRol;


RoleCard.propTypes =
  { setSelf: PropTypes.func
  , title: PropTypes.string.isRequired
  , labelProperty: PropTypes.string.isRequired


  };
fork icon0
star icon0
watch icon1

+ 5 other calls in file

1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
  children: PropTypes.node.isRequired,
  site: PropTypes.string.isRequired,
  subsite: PropTypes.string,
  darkHeaderText: PropTypes.bool,
  nonFooterBgClass: PropTypes.string,
  onUser: PropTypes.func
};
ReactPageShell.defaultProps = {
  darkHeaderText: false
};
fork icon0
star icon0
watch icon0