MCPcopy
hub / github.com/facebook/react / getElementKey

Function getElementKey

packages/react/src/ReactChildren.js:72–84  ·  packages/react/src/ReactChildren.js::getElementKey

* Generate a key string that identifies a element within a set. * * @param {*} element A element that could contain a manual key. * @param {number} index Index that is used if a manual key is not provided. * @return {string}

(element: any, index: number)

Source from the content-addressed store, hash-verified

70 * @return {string}
71 */
72function getElementKey(element: any, index: number): string {
73 class="cm">// Do some typechecking here since we call this blindly. We want to ensure
74 class="cm">// that we don't block potential future ES APIs.
75 if (typeof element === class="st">'object' && element !== null && element.key != null) {
76 class="cm">// Explicit key
77 if (__DEV__) {
78 checkKeyStringCoercion(element.key);
79 }
80 return escape(class="st">'' + element.key);
81 }
82 class="cm">// Implicit key determined by the index in the set
83 return index.toString(36);
84}
85
86function resolveThenable<T>(thenable: Thenable<T>): T {
87 switch (thenable.status) {

Callers 1

mapIntoArrayFunction · 0.85

Calls 3

checkKeyStringCoercionFunction · 0.90
escapeFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected