This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListItem.js
52 lines (47 loc) · 1.52 KB
/
ListItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { memo } from "react";
function ListItem({
getItemProps,
item,
index,
// selectedItem,
// highlightedIndex,
isSelected,
isHighlighted,
...props
}) {
// const isSelected = selectedItem?.id === item.id;
// const isHighlighted = highlightedIndex === index;
return (
<li
{...getItemProps({
index,
item,
style: {
fontWeight: isSelected ? "bold" : "normal",
backgroundColor: isHighlighted ? "lightgray" : "inherit",
},
...props,
})}
/>
);
}
// ListItem = memo(ListItem, (prevProps, nextProps) => {
// // true means do NOT rerender
// // false means DO rerender
// // these ones are easy if any of these changed, we should re-render
// if (prevProps.getItemProps !== nextProps.getItemProps) return false;
// if (prevProps.item !== nextProps.item) return false;
// if (prevProps.index !== nextProps.index) return false;
// if (prevProps.selectedItem !== nextProps.selectedItem) return false;
// // this is trickier. We should only re-render if this list item:
// // 1. was highlighted before and now it's not
// // 2. was not highlighted before and now it is
// if (prevProps.highlightedIndex !== nextProps.highlightedIndex) {
// const wasPrevHighlighted = prevProps.highlightedIndex === prevProps.index;
// const isNowHighlighted = nextProps.highlightedIndex === nextProps.index;
// return wasPrevHighlighted === isNowHighlighted;
// }
// return true;
// });
export { ListItem };
export default memo(ListItem);