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

Function validateExplicitKey

code/third-party/public/app.js:18694–18720  ·  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

18692 * @param {*} parentType element's parent's type.
18693 */
18694function validateExplicitKey(element, parentType) {
18695 if (!element._store || element._store.validated || element.key != null) {
18696 return;
18697 }
18698 element._store.validated = true;
18699
18700 var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
18701 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
18702 return;
18703 }
18704 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
18705
18706 // Usually the current owner is the offender, but if it accepts children as a
18707 // property, it may be the creator of the child that's responsible for
18708 // assigning it a key.
18709 var childOwner = '';
18710 if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
18711 // Give the component that originally created this child.
18712 childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
18713 }
18714
18715 currentlyValidatingElement = element;
18716 {
18717 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());
18718 }
18719 currentlyValidatingElement = null;
18720}
18721
18722/**
18723 * 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