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

Function warnOnInvalidKey

code/communication/public/app.js:9254–9283  ·  view source on GitHub ↗

* Warns if there is a duplicate or missing key

(child, knownKeys)

Source from the content-addressed store, hash-verified

9252 * Warns if there is a duplicate or missing key
9253 */
9254 function warnOnInvalidKey(child, knownKeys) {
9255 {
9256 if (typeof child !== 'object' || child === null) {
9257 return knownKeys;
9258 }
9259 switch (child.$$typeof) {
9260 case REACT_ELEMENT_TYPE:
9261 case REACT_PORTAL_TYPE:
9262 warnForMissingKey(child);
9263 var key = child.key;
9264 if (typeof key !== 'string') {
9265 break;
9266 }
9267 if (knownKeys === null) {
9268 knownKeys = new Set();
9269 knownKeys.add(key);
9270 break;
9271 }
9272 if (!knownKeys.has(key)) {
9273 knownKeys.add(key);
9274 break;
9275 }
9276 warning(false, 'Encountered two children with the same key, `%s`. ' + 'Keys should be unique so that components maintain their identity ' + 'across updates. Non-unique keys may cause children to be ' + 'duplicated and/or omitted — the behavior is unsupported and ' + 'could change in a future version.%s', key, getCurrentFiberStackAddendum$2());
9277 break;
9278 default:
9279 break;
9280 }
9281 }
9282 return knownKeys;
9283 }
9284
9285 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
9286 // This algorithm can't optimize by searching from boths ends since we

Callers 2

reconcileChildrenArrayFunction · 0.70

Calls 2

warningFunction · 0.85
warnForMissingKeyFunction · 0.70

Tested by

no test coverage detected