* 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)
| 19494 | * @param {*} parentType element's parent's type. |
| 19495 | */ |
| 19496 | function validateExplicitKey(element, parentType) { |
| 19497 | if (!element._store || element._store.validated || element.key != null) { |
| 19498 | return; |
| 19499 | } |
| 19500 | element._store.validated = true; |
| 19501 | |
| 19502 | var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType); |
| 19503 | if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { |
| 19504 | return; |
| 19505 | } |
| 19506 | ownerHasKeyUseWarning[currentComponentErrorInfo] = true; |
| 19507 | |
| 19508 | // Usually the current owner is the offender, but if it accepts children as a |
| 19509 | // property, it may be the creator of the child that's responsible for |
| 19510 | // assigning it a key. |
| 19511 | var childOwner = ''; |
| 19512 | if (element && element._owner && element._owner !== ReactCurrentOwner.current) { |
| 19513 | // Give the component that originally created this child. |
| 19514 | childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.'; |
| 19515 | } |
| 19516 | |
| 19517 | currentlyValidatingElement = element; |
| 19518 | { |
| 19519 | 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()); |
| 19520 | } |
| 19521 | currentlyValidatingElement = null; |
| 19522 | } |
| 19523 | |
| 19524 | /** |
| 19525 | * Ensure that every element either is passed in a static location, in an |
no test coverage detected