Home / Function/ getComponentNameFromOwner() — react Function Reference

getComponentNameFromOwner() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6dfeed4b_1363_8fef_daae_a2380cbbe37c["getComponentNameFromOwner()"]
  e2d659a0_137e_44c3_6d74_509023d250de["getComponentNameFromFiber.js"]
  6dfeed4b_1363_8fef_daae_a2380cbbe37c -->|defined in| e2d659a0_137e_44c3_6d74_509023d250de
  a8d9b36f_e843_3d12_9d3c_0e58b6a0b687["getContextName()"]
  6dfeed4b_1363_8fef_daae_a2380cbbe37c -->|calls| a8d9b36f_e843_3d12_9d3c_0e58b6a0b687
  8493dba9_c12e_b95f_0699_29d7340d40a9["getWrappedName()"]
  6dfeed4b_1363_8fef_daae_a2380cbbe37c -->|calls| 8493dba9_c12e_b95f_0699_29d7340d40a9
  style 6dfeed4b_1363_8fef_daae_a2380cbbe37c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/getComponentNameFromFiber.js lines 73–162

export function getComponentNameFromOwner(
  owner: Fiber | ReactComponentInfo,
): string | null {
  if (typeof owner.tag === 'number') {
    return getComponentNameFromFiber((owner: any));
  }
  if (typeof owner.name === 'string') {
    return owner.name;
  }
  return null;
}

export default function getComponentNameFromFiber(fiber: Fiber): string | null {
  const {tag, type} = fiber;
  switch (tag) {
    case ActivityComponent:
      return 'Activity';
    case CacheComponent:
      return 'Cache';
    case ContextConsumer:
      const consumer: ReactConsumerType<any> = (type: any);
      return getContextName(consumer._context) + '.Consumer';
    case ContextProvider:
      const context: ReactContext<any> = (type: any);
      return getContextName(context);
    case DehydratedFragment:
      return 'DehydratedFragment';
    case ForwardRef:
      return getWrappedName(type, type.render, 'ForwardRef');
    case Fragment:
      return 'Fragment';
    case HostHoistable:
    case HostSingleton:
    case HostComponent:
      // Host component type is the display name (e.g. "div", "View")
      return type;
    case HostPortal:
      return 'Portal';
    case HostRoot:
      return 'Root';
    case HostText:
      return 'Text';
    case LazyComponent:
      // Name comes from the type in this case; we don't have a tag.
      return getComponentNameFromType(type);
    case Mode:
      if (type === REACT_STRICT_MODE_TYPE) {
        // Don't be less specific than shared/getComponentNameFromType
        return 'StrictMode';
      }
      return 'Mode';
    case OffscreenComponent:
      return 'Offscreen';
    case Profiler:
      return 'Profiler';
    case ScopeComponent:
      return 'Scope';
    case SuspenseComponent:
      return 'Suspense';
    case SuspenseListComponent:
      return 'SuspenseList';
    case TracingMarkerComponent:
      return 'TracingMarker';
    case ViewTransitionComponent:
      if (enableViewTransition) {
        return 'ViewTransition';
      }
    // The display name for these tags come from the user-provided type:
    // Fallthrough
    case IncompleteClassComponent:
    case IncompleteFunctionComponent:
      if (disableLegacyMode) {
        break;
      }
    // Fallthrough
    case ClassComponent:
    case FunctionComponent:
    case MemoComponent:
    case SimpleMemoComponent:
      if (typeof type === 'function') {
        return (type: any).displayName || type.name || null;

Domain

Subdomains

Frequently Asked Questions

What does getComponentNameFromOwner() do?
getComponentNameFromOwner() is a function in the react codebase, defined in packages/react-reconciler/src/getComponentNameFromFiber.js.
Where is getComponentNameFromOwner() defined?
getComponentNameFromOwner() is defined in packages/react-reconciler/src/getComponentNameFromFiber.js at line 73.
What does getComponentNameFromOwner() call?
getComponentNameFromOwner() calls 2 function(s): getContextName, getWrappedName.

Analyze Your Own Codebase

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

Try Supermodel Free