MCPcopy Create free account
hub / github.com/Lobos/react-ui / checkPropTypes

Function checkPropTypes

docs/lib/react.js:10344–10370  ·  view source on GitHub ↗

* Assert that the props are valid * * @param {string} componentName Name of the component for error messages. * @param {object} propTypes Map of prop name to a ReactPropType * @param {object} props * @param {string} location e.g. "prop", "context", "child context" * @private

(componentName, propTypes, props, location)

Source from the content-addressed store, hash-verified

10342 * @private
10343 */
10344function checkPropTypes(componentName, propTypes, props, location) {
10345 for (var propName in propTypes) {
10346 if (propTypes.hasOwnProperty(propName)) {
10347 var error;
10348 // Prop type validation may throw. In case they do, we don't want to
10349 // fail the render phase where it didn't fail before. So we log it.
10350 // After these have been cleaned up, we'll let them throw.
10351 try {
10352 // This is intentionally an invariant that gets caught. It's the same
10353 // behavior as without this statement except with a better message.
10354 !(typeof propTypes[propName] === 'function') ? "development" !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], propName) : invariant(false) : void 0;
10355 error = propTypes[propName](props, propName, componentName, location);
10356 } catch (ex) {
10357 error = ex;
10358 }
10359 "development" !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], propName, typeof error) : void 0;
10360 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
10361 // Only monitor this failure once because there tends to be a lot of the
10362 // same error.
10363 loggedTypeFailures[error.message] = true;
10364
10365 var addendum = getDeclarationErrorAddendum();
10366 "development" !== 'production' ? warning(false, 'Failed propType: %s%s', error.message, addendum) : void 0;
10367 }
10368 }
10369 }
10370}
10371
10372/**
10373 * Given an element, validate that its props follow the propTypes definition,

Callers 1

validatePropTypesFunction · 0.70

Calls 3

warningFunction · 0.85
invariantFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…