| 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 {memo, useCallback} from 'react'; |
| 12 | import styles from './ListItem.css'; |
| 13 | |
| 14 | import type {Item} from './List'; |
| 15 | |
| 16 | type Props = { |
| 17 | item: Item, |
| 18 | removeItem: (item: Item) => void, |
| 19 | toggleItem: (item: Item) => void, |
| 20 | }; |
| 21 | |
| 22 | function ListItem({item, removeItem, toggleItem}: Props) { |
| 23 | const handleDelete = useCallback(() => { |
| 24 | removeItem(item); |
| 25 | }, [item, removeItem]); |
| 26 | |
| 27 | const handleToggle = useCallback(() => { |
| 28 | toggleItem(item); |
| 29 | }, [item, toggleItem]); |
| 30 | |
| 31 | return ( |
| 32 | <li className={styles.ListItem}> |
| 33 | <button className={styles.IconButton} onClick={handleDelete}> |
| 34 | 🗑 |
| 35 | </button> |
| 36 | <label className={styles.Label}> |
| 37 | <input |
| 38 | className={styles.Input} |
| 39 | checked={item.isComplete} |
| 40 | onChange={handleToggle} |
| 41 | type="checkbox" |
| 42 | />{' '} |
| 43 | {item.text} |
| 44 | </label> |
| 45 | </li> |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | export default memo(ListItem) as component(...props: Props); |