Home / File/ update-button.e2e.js — react Source File

update-button.e2e.js — react Source File

Architecture documentation for update-button.e2e.js, a javascript file in the react codebase. 2 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  5fd07ae1_78e6_7dcf_6498_ee3d4fb93ed5["update-button.e2e.js"]
  b5d58e15_4340_6309_2be8_bce028887672["react"]
  5fd07ae1_78e6_7dcf_6498_ee3d4fb93ed5 --> b5d58e15_4340_6309_2be8_bce028887672
  c745ba00_63aa_6e9b_0885_a745bade6cf7["react"]
  5fd07ae1_78e6_7dcf_6498_ee3d4fb93ed5 --> c745ba00_63aa_6e9b_0885_a745bade6cf7
  style 5fd07ae1_78e6_7dcf_6498_ee3d4fb93ed5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import {render} from '@testing-library/react';
import * as React from 'react';

function Button({label}) {
  const theme = useTheme();
  const style = computeStyle(theme);
  return <button color={style}>{label}</button>;
}

let currentTheme = 'light';
function useTheme() {
  'use memo';
  return currentTheme;
}

let styleComputations = 0;
function computeStyle(theme) {
  styleComputations++;
  return theme === 'light' ? 'white' : 'black';
}

test('update-button', () => {
  const {asFragment, rerender} = render(<Button label="Click me" />);
  expect(asFragment()).toMatchInlineSnapshot(`
    <DocumentFragment>
      <button
        color="white"
      >
        Click me
      </button>
    </DocumentFragment>
  `);

  // Update the label, but not the theme
  rerender(<Button label="Click again" />);
  // `computeStyle` should not be called again when Forget is enabled
  expect(styleComputations).toBe(__FORGET__ ? 1 : 2);
  expect(asFragment()).toMatchInlineSnapshot(`
    <DocumentFragment>
      <button
        color="white"
      >
        Click again
      </button>
    </DocumentFragment>
  `);

  currentTheme = 'dark';
  rerender(<Button label="Click again" />);
  expect(asFragment()).toMatchInlineSnapshot(`
    <DocumentFragment>
      <button
        color="black"
      >
        Click again
      </button>
    </DocumentFragment>
  `);

  expect(styleComputations).toBe(__FORGET__ ? 2 : 3);
});

Domain

Subdomains

Dependencies

  • react
  • react

Frequently Asked Questions

What does update-button.e2e.js do?
update-button.e2e.js is a source file in the react codebase, written in javascript. It belongs to the CompilerCore domain, BabelIntegration subdomain.
What functions are defined in update-button.e2e.js?
update-button.e2e.js defines 3 function(s): Button, computeStyle, useTheme.
What does update-button.e2e.js depend on?
update-button.e2e.js imports 2 module(s): react, react.
Where is update-button.e2e.js in the architecture?
update-button.e2e.js is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/e2e/update-button.e2e.js (domain: CompilerCore, subdomain: BabelIntegration, directory: compiler/packages/babel-plugin-react-compiler/src/__tests__/e2e).

Analyze Your Own Codebase

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

Try Supermodel Free