2019-01-23 03:04:37 +08:00
|
|
|
// @flow
|
|
|
|
|
|
2019-03-21 00:39:14 +08:00
|
|
|
import React, { memo, useCallback } from 'react';
|
2019-01-23 03:04:37 +08:00
|
|
|
import styles from './ListItem.css';
|
|
|
|
|
|
2019-01-24 00:45:19 +08:00
|
|
|
import type { Item } from './List';
|
2019-01-23 03:04:37 +08:00
|
|
|
|
|
|
|
|
type Props = {|
|
|
|
|
|
item: Item,
|
|
|
|
|
removeItem: (item: Item) => void,
|
|
|
|
|
toggleItem: (item: Item) => void,
|
|
|
|
|
|};
|
|
|
|
|
|
2019-03-21 00:39:14 +08:00
|
|
|
function ListItem({ item, removeItem, toggleItem }: Props) {
|
2019-01-23 03:04:37 +08:00
|
|
|
const handleDelete = useCallback(() => {
|
|
|
|
|
removeItem(item);
|
|
|
|
|
}, [item, removeItem]);
|
|
|
|
|
|
|
|
|
|
const handleToggle = useCallback(() => {
|
|
|
|
|
toggleItem(item);
|
|
|
|
|
}, [item, toggleItem]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<li className={styles.ListItem}>
|
2019-01-24 00:45:19 +08:00
|
|
|
<button className={styles.IconButton} onClick={handleDelete}>
|
|
|
|
|
🗑
|
|
|
|
|
</button>
|
2019-01-23 03:04:37 +08:00
|
|
|
<label className={styles.Label}>
|
|
|
|
|
<input
|
|
|
|
|
className={styles.Input}
|
|
|
|
|
checked={item.isComplete}
|
|
|
|
|
onChange={handleToggle}
|
|
|
|
|
type="checkbox"
|
2019-01-24 00:45:19 +08:00
|
|
|
/>{' '}
|
|
|
|
|
{item.text}
|
2019-01-23 03:04:37 +08:00
|
|
|
</label>
|
|
|
|
|
</li>
|
2019-01-24 00:45:19 +08:00
|
|
|
);
|
|
|
|
|
}
|
2019-03-21 00:39:14 +08:00
|
|
|
|
|
|
|
|
export default memo<Props>(ListItem);
|