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

Function describeElementType

packages/shared/ReactSerializationErrors.js:137–169  ·  view source on GitHub ↗
(type: any)

Source from the content-addressed store, hash-verified

135}
136
137function describeElementType(type: any): string {
138 if (typeof type === 'string') {
139 return type;
140 }
141 switch (type) {
142 case REACT_SUSPENSE_TYPE:
143 return 'Suspense';
144 case REACT_SUSPENSE_LIST_TYPE:
145 return 'SuspenseList';
146 case REACT_VIEW_TRANSITION_TYPE:
147 if (enableViewTransition) {
148 return 'ViewTransition';
149 }
150 }
151 if (typeof type === 'object') {
152 switch (type.$$typeof) {
153 case REACT_FORWARD_REF_TYPE:
154 return describeElementType(type.render);
155 case REACT_MEMO_TYPE:
156 return describeElementType(type.type);
157 case REACT_LAZY_TYPE: {
158 const lazyComponent: LazyComponent<any, any> = (type: any);
159 const payload = lazyComponent._payload;
160 const init = lazyComponent._init;
161 try {
162 // Lazy may contain any component type so we recursively resolve it.
163 return describeElementType(init(payload));
164 } catch (x) {}
165 }
166 }
167 }
168 return '';
169}
170
171const CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
172

Callers 1

Calls 1

initFunction · 0.50

Tested by

no test coverage detected