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

Function validateExplicitKey

code/new-context-api/public/app.js:18822–18848  ·  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

18820 * @param {*} parentType element's parent's type.
18821 */
18822function validateExplicitKey(element, parentType) {
18823 if (!element._store || element._store.validated || element.key != null) {
18824 return;
18825 }
18826 element._store.validated = true;
18827
18828 var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
18829 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
18830 return;
18831 }
18832 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
18833
18834 // Usually the current owner is the offender, but if it accepts children as a
18835 // property, it may be the creator of the child that's responsible for
18836 // assigning it a key.
18837 var childOwner = '';
18838 if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
18839 // Give the component that originally created this child.
18840 childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
18841 }
18842
18843 currentlyValidatingElement = element;
18844 {
18845 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());
18846 }
18847 currentlyValidatingElement = null;
18848}
18849
18850/**
18851 * 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