Home / File/ LargeSubtree.js — react Source File

LargeSubtree.js — react Source File

Architecture documentation for LargeSubtree.js, a javascript file in the react codebase. 1 imports, 1 dependents.

File javascript BabelCompiler Validation 1 imports 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  aa439c83_a130_686b_6832_de19aa600273["LargeSubtree.js"]
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  aa439c83_a130_686b_6832_de19aa600273 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  e4a0282b_ebaf_8a3f_151f_786265e42da2["index.js"]
  e4a0282b_ebaf_8a3f_151f_786265e42da2 --> aa439c83_a130_686b_6832_de19aa600273
  style aa439c83_a130_686b_6832_de19aa600273 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

import * as React from 'react';

function generateArray(size: number) {
  return Array.from({length: size}, () => Math.floor(Math.random() * size));
}

const arr = generateArray(50000);

export default function LargeSubtree(): React.Node {
  const [showList, setShowList] = React.useState(false);
  const toggleList = () => {
    const startTime = performance.now();
    setShowList(!showList);
    // requestAnimationFrame should happen after render+commit is done
    window.requestAnimationFrame(() => {
      const afterRenderTime = performance.now();
      console.log(
        `Time spent on ${showList ? 'unmounting' : 'mounting'} the subtree: ${
          afterRenderTime - startTime
        }ms`,
      );
    });
  };
  return (
    <div>
      <h2>Mount/Unmount a large subtree</h2>
      <p>Click the button to toggle the state. Open console for results.</p>
      <button onClick={toggleList}>toggle</button>
      <ul>
        <li key="dummy">dummy item</li>
        {showList && arr.map((num, idx) => <li key={idx}>{num}</li>)}
      </ul>
    </div>
  );
}

Domain

Subdomains

Dependencies

  • react

Frequently Asked Questions

What does LargeSubtree.js do?
LargeSubtree.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in LargeSubtree.js?
LargeSubtree.js defines 2 function(s): LargeSubtree, generateArray.
What does LargeSubtree.js depend on?
LargeSubtree.js imports 1 module(s): react.
What files import LargeSubtree.js?
LargeSubtree.js is imported by 1 file(s): index.js.
Where is LargeSubtree.js in the architecture?
LargeSubtree.js is located at packages/react-devtools-shell/src/perf-regression/apps/LargeSubtree.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shell/src/perf-regression/apps).

Analyze Your Own Codebase

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

Try Supermodel Free