* Shared warning and monitoring code for the key warnings. * * @internal * @param {string} warningID The id used when logging. * @param {string} message The base warning that gets output. * @param {ReactComponent} component Component that requires a key. * @param {*} parentType component
(warningID, message, component, parentType)
| 8740 | * @param {*} parentType component's parent's type. |
| 8741 | */ |
| 8742 | function warnAndMonitorForKeyUse(warningID, message, component, parentType) { |
| 8743 | var ownerName = getCurrentOwnerDisplayName(); |
| 8744 | var parentName = parentType.displayName; |
| 8745 | |
| 8746 | var useName = ownerName || parentName; |
| 8747 | var memoizer = ownerHasKeyUseWarning[warningID]; |
| 8748 | if (memoizer.hasOwnProperty(useName)) { |
| 8749 | return; |
| 8750 | } |
| 8751 | memoizer[useName] = true; |
| 8752 | |
| 8753 | message += ownerName ? |
| 8754 | (" Check the render method of " + ownerName + ".") : |
| 8755 | (" Check the renderComponent call using <" + parentName + ">."); |
| 8756 | |
| 8757 | // Usually the current owner is the offender, but if it accepts children as a |
| 8758 | // property, it may be the creator of the child that's responsible for |
| 8759 | // assigning it a key. |
| 8760 | var childOwnerName = null; |
| 8761 | if (component._owner && component._owner !== ReactCurrentOwner.current) { |
| 8762 | // Name of the component that originally created this child. |
| 8763 | childOwnerName = component._owner.constructor.displayName; |
| 8764 | |
| 8765 | message += (" It was passed a child from " + childOwnerName + "."); |
| 8766 | } |
| 8767 | |
| 8768 | message += ' See http://fb.me/react-warning-keys for more information.'; |
| 8769 | monitorCodeUse(warningID, { |
| 8770 | component: useName, |
| 8771 | componentOwner: childOwnerName |
| 8772 | }); |
| 8773 | console.warn(message); |
| 8774 | } |
| 8775 | |
| 8776 | /** |
| 8777 | * Log that we're using an object map. We're considering deprecating this |
no test coverage detected