MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / validateExplicitKey

Function validateExplicitKey

code/styling/public/app.js:19461–19487  ·  view source on GitHub ↗

* Warn if the element doesn't have an explicit key assigned to it. * This element is in an array. The array could grow and shrink or be * reordered. All children that haven't already been validated are required to * have a "key" property assigned to it. Error statuses are cached so a warning * w

(element, parentType)

Source from the content-addressed store, hash-verified

19459 * @param {*} parentType element's parent's type.
19460 */
19461function validateExplicitKey(element, parentType) {
19462 if (!element._store || element._store.validated || element.key != null) {
19463 return;
19464 }
19465 element._store.validated = true;
19466
19467 var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
19468 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
19469 return;
19470 }
19471 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
19472
19473 // Usually the current owner is the offender, but if it accepts children as a
19474 // property, it may be the creator of the child that's responsible for
19475 // assigning it a key.
19476 var childOwner = '';
19477 if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
19478 // Give the component that originally created this child.
19479 childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
19480 }
19481
19482 currentlyValidatingElement = element;
19483 {
19484 warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.%s', currentComponentErrorInfo, childOwner, getStackAddendum());
19485 }
19486 currentlyValidatingElement = null;
19487}
19488
19489/**
19490 * Ensure that every element either is passed in a static location, in an

Callers 1

validateChildKeysFunction · 0.70

Calls 4

warningFunction · 0.85
getComponentNameFunction · 0.70
getStackAddendumFunction · 0.70

Tested by

no test coverage detected