1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import * as React from 'react';
    
  11. import {useRef, useState} from 'react';
    
  12. 
    
  13. export default function App(): React.Node {
    
  14.   return <List />;
    
  15. }
    
  16. 
    
  17. function List() {
    
  18.   const [items, setItems] = useState(['one', 'two', 'three']);
    
  19.   const inputRef = useRef(null);
    
  20. 
    
  21.   const addItem = () => {
    
  22.     const input = ((inputRef.current: any): HTMLInputElement);
    
  23.     const text = input.value;
    
  24.     input.value = '';
    
  25. 
    
  26.     if (text) {
    
  27.       setItems([...items, text]);
    
  28.     }
    
  29.   };
    
  30. 
    
  31.   return (
    
  32.     <>
    
  33.       <input ref={inputRef} data-testname="AddItemInput" />
    
  34.       <button data-testname="AddItemButton" onClick={addItem}>
    
  35.         Add Item
    
  36.       </button>
    
  37.       <ul data-testname="List">
    
  38.         {items.map((label, index) => (
    
  39.           <ListItem key={index} label={label} />
    
  40.         ))}
    
  41.       </ul>
    
  42.     </>
    
  43.   );
    
  44. }
    
  45. 
    
  46. // $FlowFixMe[missing-local-annot]
    
  47. function ListItem({label}) {
    
  48.   return <li data-testname="ListItem">{label}</li>;
    
  49. }