* 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)
| 19552 | * @param {*} parentType element's parent's type. |
| 19553 | */ |
| 19554 | function validateExplicitKey(element, parentType) { |
| 19555 | if (!element._store || element._store.validated || element.key != null) { |
| 19556 | return; |
| 19557 | } |
| 19558 | element._store.validated = true; |
| 19559 | |
| 19560 | var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType); |
| 19561 | if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { |
| 19562 | return; |
| 19563 | } |
| 19564 | ownerHasKeyUseWarning[currentComponentErrorInfo] = true; |
| 19565 | |
| 19566 | // Usually the current owner is the offender, but if it accepts children as a |
| 19567 | // property, it may be the creator of the child that's responsible for |
| 19568 | // assigning it a key. |
| 19569 | var childOwner = ''; |
| 19570 | if (element && element._owner && element._owner !== ReactCurrentOwner.current) { |
| 19571 | // Give the component that originally created this child. |
| 19572 | childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.'; |
| 19573 | } |
| 19574 | |
| 19575 | currentlyValidatingElement = element; |
| 19576 | { |
| 19577 | 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()); |
| 19578 | } |
| 19579 | currentlyValidatingElement = null; |
| 19580 | } |
| 19581 | |
| 19582 | /** |
| 19583 | * Ensure that every element either is passed in a static location, in an |
no test coverage detected