Home / File/ List.js — react Source File

List.js — react Source File

Architecture documentation for List.js, a javascript file in the react codebase. 4 imports, 2 dependents.

File javascript BabelCompiler Validation 4 imports 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  5fd1ffe1_dc6c_f2c3_53aa_316f8da83850["List.js"]
  600c7a04_7bc8_1cb9_5303_8398c843ca05["ListItem.js"]
  5fd1ffe1_dc6c_f2c3_53aa_316f8da83850 --> 600c7a04_7bc8_1cb9_5303_8398c843ca05
  079b793c_7dca_fbcb_0e8b_ea8a0d43a9ae["ListItem"]
  5fd1ffe1_dc6c_f2c3_53aa_316f8da83850 --> 079b793c_7dca_fbcb_0e8b_ea8a0d43a9ae
  baa01ee6_47ed_fcb5_5e84_80459c58d36b["List.css"]
  5fd1ffe1_dc6c_f2c3_53aa_316f8da83850 --> baa01ee6_47ed_fcb5_5e84_80459c58d36b
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  5fd1ffe1_dc6c_f2c3_53aa_316f8da83850 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  600c7a04_7bc8_1cb9_5303_8398c843ca05["ListItem.js"]
  600c7a04_7bc8_1cb9_5303_8398c843ca05 --> 5fd1ffe1_dc6c_f2c3_53aa_316f8da83850
  06a7c3d2_ab87_2c22_78f1_74eb83666c52["index.js"]
  06a7c3d2_ab87_2c22_78f1_74eb83666c52 --> 5fd1ffe1_dc6c_f2c3_53aa_316f8da83850
  style 5fd1ffe1_dc6c_f2c3_53aa_316f8da83850 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, useCallback, useState} from 'react';
import ListItem from './ListItem';
import styles from './List.css';

export type Item = {
  id: number,
  isComplete: boolean,
  text: string,
};

type Props = {};

export default function List(props: Props): React.Node {
  const [newItemText, setNewItemText] = useState<string>('');
  const [items, setItems] = useState<Array<Item>>([
    {id: 1, isComplete: true, text: 'First'},
    {id: 2, isComplete: true, text: 'Second'},
    {id: 3, isComplete: false, text: 'Third'},
  ]);
  const [uid, setUID] = useState<number>(4);

  const handleClick = useCallback(() => {
    if (newItemText !== '') {
      setItems([
        ...items,
        {
          id: uid,
          isComplete: false,
          text: newItemText,
        },
      ]);
      setUID(uid + 1);
      setNewItemText('');
    }
  }, [newItemText, items, uid]);

  const handleKeyPress = useCallback(
    (event: $FlowFixMe) => {
      if (event.key === 'Enter') {
        handleClick();
      }
    },
    [handleClick],
  );

  const handleChange = useCallback(
    (event: $FlowFixMe) => {
      setNewItemText(event.currentTarget.value);
    },
    [setNewItemText],
  );

  const removeItem = useCallback(
    (itemToRemove: $FlowFixMe) =>
      setItems(items.filter(item => item !== itemToRemove)),
    [items],
  );

  const toggleItem = useCallback(
    (itemToToggle: $FlowFixMe) => {
      // Dont use indexOf()
      // because editing props in DevTools creates a new Object.
      const index = items.findIndex(item => item.id === itemToToggle.id);

      setItems(
        items
          .slice(0, index)
          .concat({
            ...itemToToggle,
            isComplete: !itemToToggle.isComplete,
          })
          .concat(items.slice(index + 1)),
      );
    },
    [items],
  );

  return (
    <Fragment>
      <h1>List</h1>
      <input
        type="text"
        placeholder="New list item..."
        className={styles.Input}
        value={newItemText}
        onChange={handleChange}
        onKeyPress={handleKeyPress}
      />
      <button
        className={styles.IconButton}
        disabled={newItemText === ''}
        onClick={handleClick}>
        <span role="img" aria-label="Add item">
          ➕
        </span>
      </button>
      <ul className={styles.List}>
        {items.map(item => (
          <ListItem
            key={item.id}
            item={item}
            removeItem={removeItem}
            toggleItem={toggleItem}
          />
        ))}
      </ul>
    </Fragment>
  );
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free