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

Function validateExplicitKey

code/composition/public/app.js:19599–19625  ·  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

19597 * @param {*} parentType element's parent's type.
19598 */
19599function validateExplicitKey(element, parentType) {
19600 if (!element._store || element._store.validated || element.key != null) {
19601 return;
19602 }
19603 element._store.validated = true;
19604
19605 var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
19606 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
19607 return;
19608 }
19609 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
19610
19611 // Usually the current owner is the offender, but if it accepts children as a
19612 // property, it may be the creator of the child that's responsible for
19613 // assigning it a key.
19614 var childOwner = '';
19615 if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
19616 // Give the component that originally created this child.
19617 childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
19618 }
19619
19620 currentlyValidatingElement = element;
19621 {
19622 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());
19623 }
19624 currentlyValidatingElement = null;
19625}
19626
19627/**
19628 * 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