Home / File/ index.js — react Source File

index.js — react Source File

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

File javascript BabelCompiler Validation 1 imports 1 dependents 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  1e6dd1fc_349f_47a9_79c2_8b7e89c3cc44["index.js"]
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  1e6dd1fc_349f_47a9_79c2_8b7e89c3cc44 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  30d76895_4832_9ca3_9e81_e0cdf028c09c["index.js"]
  30d76895_4832_9ca3_9e81_e0cdf028c09c --> 1e6dd1fc_349f_47a9_79c2_8b7e89c3cc44
  style 1e6dd1fc_349f_47a9_79c2_8b7e89c3cc44 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.
 *
 * @flow
 */

import * as React from 'react';
import {Fragment} from 'react';

class ErrorBoundary extends React.Component {
  state: {hasError: boolean} = {hasError: false};

  static getDerivedStateFromError(error: any): {hasError: boolean} {
    return {hasError: true};
  }

  render(): any {
    const {hasError} = this.state;
    if (hasError) {
      return (
        <div
          style={{
            color: 'red',
            border: '1px solid red',
            borderRadius: '0.25rem',
            margin: '0.5rem',
            padding: '0.5rem',
          }}>
          An error was thrown.
        </div>
      );
    }

    const {children} = this.props;
    return (
      <div
        style={{
          border: '1px solid gray',
          borderRadius: '0.25rem',
          margin: '0.5rem',
          padding: '0.5rem',
        }}>
        {children}
      </div>
    );
  }
}

// $FlowFixMe[missing-local-annot]
function Component({label}) {
  return <div>{label}</div>;
}

export default function ErrorBoundaries(): React.Node {
  return (
    <Fragment>
      <h1>Nested error boundaries demo</h1>
      <ErrorBoundary>
        <Component label="Outer component" />
        <ErrorBoundary>
          <Component label="Inner component" />
        </ErrorBoundary>
      </ErrorBoundary>
      <ErrorBoundary>
        <Component label="Neighbour component" />
      </ErrorBoundary>
    </Fragment>
  );
}

Domain

Subdomains

Classes

Dependencies

  • react

Frequently Asked Questions

What does index.js do?
index.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 index.js?
index.js defines 2 function(s): Component, ErrorBoundaries.
What does index.js depend on?
index.js imports 1 module(s): react.
What files import index.js?
index.js is imported by 1 file(s): index.js.
Where is index.js in the architecture?
index.js is located at packages/react-devtools-shell/src/app/ErrorBoundaries/index.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shell/src/app/ErrorBoundaries).

Analyze Your Own Codebase

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

Try Supermodel Free