MCPcopy Create free account
hub / github.com/reactjs/react-rails / warnOnInvalidKey

Function warnOnInvalidKey

lib/assets/react-source/development/react.js:17469–17503  ·  view source on GitHub ↗

* Warns if there is a duplicate or missing key

(child, knownKeys)

Source from the content-addressed store, hash-verified

17467
17468
17469 function warnOnInvalidKey(child, knownKeys) {
17470 {
17471 if (typeof child !== 'object' || child === null) {
17472 return knownKeys;
17473 }
17474
17475 switch (child.$$typeof) {
17476 case REACT_ELEMENT_TYPE:
17477 case REACT_PORTAL_TYPE:
17478 warnForMissingKey(child);
17479 var key = child.key;
17480
17481 if (typeof key !== 'string') {
17482 break;
17483 }
17484
17485 if (knownKeys === null) {
17486 knownKeys = new Set();
17487 knownKeys.add(key);
17488 break;
17489 }
17490
17491 if (!knownKeys.has(key)) {
17492 knownKeys.add(key);
17493 break;
17494 }
17495
17496 error('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.', key);
17497
17498 break;
17499 }
17500 }
17501
17502 return knownKeys;
17503 }
17504
17505 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
17506 // This algorithm can't optimize by searching from both ends since we

Callers 2

reconcileChildrenArrayFunction · 0.85

Calls 2

warnForMissingKeyFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected