MCPcopy Index your code
hub / github.com/reactjs/react-rails / validateExplicitKey

Function validateExplicitKey

lib/assets/react-source/development/react.js:1996–2026  ·  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

(element, parentType)

Source from the content-addressed store, hash-verified

1994
1995
1996 function validateExplicitKey(element, parentType) {
1997 if (!element._store || element._store.validated || element.key != null) {
1998 return;
1999 }
2000
2001 element._store.validated = true;
2002 var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
2003
2004 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
2005 return;
2006 }
2007
2008 ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
2009 // property, it may be the creator of the child that's responsible for
2010 // assigning it a key.
2011
2012 var childOwner = '';
2013
2014 if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
2015 // Give the component that originally created this child.
2016 childOwner = " It was passed a child from " + getComponentName(element._owner.type) + ".";
2017 }
2018
2019 setCurrentlyValidatingElement(element);
2020
2021 {
2022 error('Each child in a list should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.', currentComponentErrorInfo, childOwner);
2023 }
2024
2025 setCurrentlyValidatingElement(null);
2026 }
2027 /**
2028 * Ensure that every element either is passed in a static location, in an
2029 * array with an explicit keys property defined, or in an object literal

Callers 1

validateChildKeysFunction · 0.70

Calls 4

getComponentNameFunction · 0.70
errorFunction · 0.70

Tested by

no test coverage detected