MCPcopy Create free account
hub / github.com/microsoft/SandDance / warnOnInvalidKey

Function warnOnInvalidKey

docs/external/js/react-dom.development.js:13909–13943  ·  view source on GitHub ↗

* Warns if there is a duplicate or missing key

(child, knownKeys)

Source from the content-addressed store, hash-verified

13907
13908
13909 function warnOnInvalidKey(child, knownKeys) {
13910 {
13911 if (typeof child !== 'object' || child === null) {
13912 return knownKeys;
13913 }
13914
13915 switch (child.$$typeof) {
13916 case REACT_ELEMENT_TYPE:
13917 case REACT_PORTAL_TYPE:
13918 warnForMissingKey(child);
13919 var key = child.key;
13920
13921 if (typeof key !== 'string') {
13922 break;
13923 }
13924
13925 if (knownKeys === null) {
13926 knownKeys = new Set();
13927 knownKeys.add(key);
13928 break;
13929 }
13930
13931 if (!knownKeys.has(key)) {
13932 knownKeys.add(key);
13933 break;
13934 }
13935
13936 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);
13937
13938 break;
13939 }
13940 }
13941
13942 return knownKeys;
13943 }
13944
13945 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
13946 // This algorithm can't optimize by searching from both ends since we

Callers 2

reconcileChildrenArrayFunction · 0.85

Calls 4

warnForMissingKeyFunction · 0.85
errorFunction · 0.70
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected