Home / Function/ getComponentNameFromType() — react Function Reference

getComponentNameFromType() — react Function Reference

Architecture documentation for the getComponentNameFromType() function in getComponentNameFromType.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  90949571_0369_6d18_87d7_7e2130ff7bfd["getComponentNameFromType()"]
  d1749588_72f0_305a_3ea3_ab196eddbd95["getComponentNameFromType.js"]
  90949571_0369_6d18_87d7_7e2130ff7bfd -->|defined in| d1749588_72f0_305a_3ea3_ab196eddbd95
  f57b9904_83aa_6b26_ca52_4cf0fa795144["addValueToProperties()"]
  f57b9904_83aa_6b26_ca52_4cf0fa795144 -->|calls| 90949571_0369_6d18_87d7_7e2130ff7bfd
  8e0d87e0_ef2f_ba84_1936_008118cabb0e["addObjectDiffToProperties()"]
  8e0d87e0_ef2f_ba84_1936_008118cabb0e -->|calls| 90949571_0369_6d18_87d7_7e2130ff7bfd
  1860c3e3_a7a1_3afe_e911_41da1cc09740["getContextName()"]
  90949571_0369_6d18_87d7_7e2130ff7bfd -->|calls| 1860c3e3_a7a1_3afe_e911_41da1cc09740
  3b4de844_c430_9dbf_8d49_674121ce4b6a["getWrappedName()"]
  90949571_0369_6d18_87d7_7e2130ff7bfd -->|calls| 3b4de844_c430_9dbf_8d49_674121ce4b6a
  style 90949571_0369_6d18_87d7_7e2130ff7bfd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shared/getComponentNameFromType.js lines 57–132

export default function getComponentNameFromType(type: mixed): string | null {
  if (type == null) {
    // Host root, text node or just invalid type.
    return null;
  }
  if (typeof type === 'function') {
    if ((type: any).$$typeof === REACT_CLIENT_REFERENCE) {
      // TODO: Create a convention for naming client references with debug info.
      return null;
    }
    return (type: any).displayName || type.name || null;
  }
  if (typeof type === 'string') {
    return type;
  }
  switch (type) {
    case REACT_FRAGMENT_TYPE:
      return 'Fragment';
    case REACT_PROFILER_TYPE:
      return 'Profiler';
    case REACT_STRICT_MODE_TYPE:
      return 'StrictMode';
    case REACT_SUSPENSE_TYPE:
      return 'Suspense';
    case REACT_SUSPENSE_LIST_TYPE:
      return 'SuspenseList';
    case REACT_ACTIVITY_TYPE:
      return 'Activity';
    case REACT_VIEW_TRANSITION_TYPE:
      if (enableViewTransition) {
        return 'ViewTransition';
      }
    // Fall through
    case REACT_TRACING_MARKER_TYPE:
      if (enableTransitionTracing) {
        return 'TracingMarker';
      }
  }
  if (typeof type === 'object') {
    if (__DEV__) {
      if (typeof (type: any).tag === 'number') {
        console.error(
          'Received an unexpected object in getComponentNameFromType(). ' +
            'This is likely a bug in React. Please file an issue.',
        );
      }
    }
    switch (type.$$typeof) {
      case REACT_PORTAL_TYPE:
        return 'Portal';
      case REACT_CONTEXT_TYPE:
        const context: ReactContext<any> = (type: any);
        return getContextName(context);
      case REACT_CONSUMER_TYPE:
        const consumer: ReactConsumerType<any> = (type: any);
        return getContextName(consumer._context) + '.Consumer';
      case REACT_FORWARD_REF_TYPE:
        return getWrappedName(type, type.render, 'ForwardRef');
      case REACT_MEMO_TYPE:
        const outerName = (type: any).displayName || null;
        if (outerName !== null) {
          return outerName;
        }
        return getComponentNameFromType(type.type) || 'Memo';
      case REACT_LAZY_TYPE: {
        const lazyComponent: LazyComponent<any, any> = (type: any);
        const payload = lazyComponent._payload;
        const init = lazyComponent._init;
        try {
          return getComponentNameFromType(init(payload));
        } catch (x) {
          return null;
        }
      }
    }
  }

Domain

Subdomains

Frequently Asked Questions

What does getComponentNameFromType() do?
getComponentNameFromType() is a function in the react codebase, defined in packages/shared/getComponentNameFromType.js.
Where is getComponentNameFromType() defined?
getComponentNameFromType() is defined in packages/shared/getComponentNameFromType.js at line 57.
What does getComponentNameFromType() call?
getComponentNameFromType() calls 2 function(s): getContextName, getWrappedName.
What calls getComponentNameFromType()?
getComponentNameFromType() is called by 2 function(s): addObjectDiffToProperties, addValueToProperties.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free