Home / Function/ isComponentOrHookLike() — react Function Reference

isComponentOrHookLike() — react Function Reference

Architecture documentation for the isComponentOrHookLike() function in babel-plugin-annotate-react-code.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  40539f87_cad8_e5ab_baf5_c8916ae353cf["isComponentOrHookLike()"]
  90fd4a4d_9742_70a7_9512_f9dd5b565200["babel-plugin-annotate-react-code.ts"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|defined in| 90fd4a4d_9742_70a7_9512_f9dd5b565200
  885dabed_4ea6_4b50_13ff_6ab9e94c743c["shouldVisit()"]
  885dabed_4ea6_4b50_13ff_6ab9e94c743c -->|calls| 40539f87_cad8_e5ab_baf5_c8916ae353cf
  c0984882_814d_5695_4f67_3f3356e0f3eb["getFunctionName()"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|calls| c0984882_814d_5695_4f67_3f3356e0f3eb
  386d76a3_008b_7f70_bd91_8323ec18bd5c["isComponentName()"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|calls| 386d76a3_008b_7f70_bd91_8323ec18bd5c
  91675464_ecf7_5d45_b9ac_a40f0b6d6c65["callsHooksOrCreatesJsx()"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|calls| 91675464_ecf7_5d45_b9ac_a40f0b6d6c65
  4280acf5_f565_fbf1_6a6e_06da2024d5cf["isHook()"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|calls| 4280acf5_f565_fbf1_6a6e_06da2024d5cf
  e6a32231_fcbe_0fab_a874_68eff05ef0d7["isForwardRefCallback()"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|calls| e6a32231_fcbe_0fab_a874_68eff05ef0d7
  42add05a_c196_1d10_3e0f_b8aa6b250328["isMemoCallback()"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|calls| 42add05a_c196_1d10_3e0f_b8aa6b250328
  style 40539f87_cad8_e5ab_baf5_c8916ae353cf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/scripts/babel-plugin-annotate-react-code.ts lines 101–137

function isComponentOrHookLike(
  node: NodePath<
    t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
  >,
): boolean {
  const functionName = getFunctionName(node);
  // Check if the name is component or hook like:
  if (functionName !== null && isComponentName(functionName)) {
    return (
      // As an added check we also look for hook invocations or JSX
      callsHooksOrCreatesJsx(node) &&
      /*
       * and avoid helper functions that take more than one argument
       * helpers are _usually_ named with lowercase, but some code may
       * violate this rule
       */
      node.get('params').length <= 1
    );
  } else if (functionName !== null && isHook(functionName)) {
    // Hooks have hook invocations or JSX, but can take any # of arguments
    return callsHooksOrCreatesJsx(node);
  }

  /*
   * Otherwise for function or arrow function expressions, check if they
   * appear as the argument to React.forwardRef() or React.memo():
   */
  if (node.isFunctionExpression() || node.isArrowFunctionExpression()) {
    if (isForwardRefCallback(node) || isMemoCallback(node)) {
      // As an added check we also look for hook invocations or JSX
      return callsHooksOrCreatesJsx(node);
    } else {
      return false;
    }
  }
  return false;
}

Subdomains

Called By

Frequently Asked Questions

What does isComponentOrHookLike() do?
isComponentOrHookLike() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/scripts/babel-plugin-annotate-react-code.ts.
Where is isComponentOrHookLike() defined?
isComponentOrHookLike() is defined in compiler/packages/babel-plugin-react-compiler/scripts/babel-plugin-annotate-react-code.ts at line 101.
What does isComponentOrHookLike() call?
isComponentOrHookLike() calls 6 function(s): callsHooksOrCreatesJsx, getFunctionName, isComponentName, isForwardRefCallback, isHook, isMemoCallback.
What calls isComponentOrHookLike()?
isComponentOrHookLike() is called by 1 function(s): shouldVisit.

Analyze Your Own Codebase

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

Try Supermodel Free