Home / Function/ Component() — react Function Reference

Component() — react Function Reference

Architecture documentation for the Component() function in fast-refresh-refresh-on-const-changes-dev.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  17bd78c0_6000_88bd_0f9b_4d6478f93d9d["Component()"]
  ffc0147c_6b5a_3942_bb71_d73a6d88eb43["fast-refresh-refresh-on-const-changes-dev.js"]
  17bd78c0_6000_88bd_0f9b_4d6478f93d9d -->|defined in| ffc0147c_6b5a_3942_bb71_d73a6d88eb43
  53282f42_bfec_53a9_2e65_73fbe4f43e52["unsafeResetConst()"]
  17bd78c0_6000_88bd_0f9b_4d6478f93d9d -->|calls| 53282f42_bfec_53a9_2e65_73fbe4f43e52
  89961f58_39e5_9719_0d6e_5a2213f632c1["unsafeUpdateConst()"]
  17bd78c0_6000_88bd_0f9b_4d6478f93d9d -->|calls| 89961f58_39e5_9719_0d6e_5a2213f632c1
  style 17bd78c0_6000_88bd_0f9b_4d6478f93d9d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fast-refresh-refresh-on-const-changes-dev.js lines 15–32

function Component() {
  useState(() => {
    // unsafe: reset the constant when first rendering the instance
    unsafeResetConst();
  });
  // UNSAFE! changing a module variable that is read by a component is normally
  // unsafe, but in this case we're simulating a fast refresh between each render
  unsafeUpdateConst();

  // TODO: In fast refresh mode (@enableResetCacheOnSourceFileChanges) Forget should
  // reset on changes to globals that impact the component/hook, effectively memoizing
  // as if value was reactive. However, we don't want to actually treat globals as
  // reactive (though that would be trivial) since it could change compilation too much
  // btw dev and prod. Instead, we should reset the cache via a secondary mechanism.
  const value = useMemo(() => [{pretendConst}], [pretendConst]);

  return <ValidateMemoization inputs={[pretendConst]} output={value} />;
}

Subdomains

Frequently Asked Questions

What does Component() do?
Component() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fast-refresh-refresh-on-const-changes-dev.js.
Where is Component() defined?
Component() is defined in compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fast-refresh-refresh-on-const-changes-dev.js at line 15.
What does Component() call?
Component() calls 2 function(s): unsafeResetConst, unsafeUpdateConst.

Analyze Your Own Codebase

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

Try Supermodel Free