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

Function getDisplayName

packages/react-devtools-shared/src/utils.js:146–168  ·  view source on GitHub ↗
(
  type: Function,
  fallbackName: string = 'Anonymous',
)

Source from the content-addressed store, hash-verified

144}
145
146export function getDisplayName(
147 type: Function,
148 fallbackName: string = 'Anonymous',
149): string {
150 const nameFromCache = cachedDisplayNames.get(type);
151 if (nameFromCache != null) {
152 return nameFromCache;
153 }
154
155 let displayName = fallbackName;
156
157 // The displayName property is not guaranteed to be a string.
158 // It's only safe to use for our purposes if it's a string.
159 // github.com/facebook/react-devtools/issues/803
160 if (typeof type.displayName === 'string') {
161 displayName = type.displayName;
162 } else if (typeof type.name === 'string' && type.name !== '') {
163 displayName = type.name;
164 }
165
166 cachedDisplayNames.set(type, displayName);
167 return displayName;
168}
169
170let uidCounter: number = 0;
171

Callers 5

getDataFunction · 0.90
getDisplayNameForFiberFunction · 0.90
utils-test.jsFile · 0.90
getWrappedDisplayNameFunction · 0.85

Calls 2

setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected