fix: crash when an item was removed from Virtuouso

This was a pesky bug. Basically the `props.items.length` did not get updated which resulted in the `index` being always one greater than actual. Since `index[out-of-range]` is `undefined` in JS, the app crashed as it could not find any prop. Very pesky. Fixed it however.
This commit is contained in:
thecodrr
2020-04-21 12:42:58 +05:00
parent 7c00a281e4
commit c9866fe6c7
3 changed files with 10 additions and 7 deletions

View File

@@ -44,7 +44,11 @@ function ListContainer(props) {
overflowX: "hidden",
}}
totalCount={props.items.length}
item={(index) => props.item(index, props.items[index])}
item={(index) => {
const item = props.items[index];
if (!item) return null;
return props.item(index, item);
}}
/>
) : null}
</Flex>

View File

@@ -163,8 +163,6 @@ export default React.memo(Note, function (prevProps, nextProps) {
const prevItem = prevProps.item;
const nextItem = nextProps.item;
// do not update if the item was removed
if (!prevItem || !nextItem) return true;
return (
prevItem.pinned === nextItem.pinned &&
prevItem.favorite === nextItem.favorite &&

View File

@@ -42,11 +42,12 @@ function Home() {
</Box>
);
}}
item={(index, groupIndex) =>
notes.groupCounts[groupIndex] && (
item={(index, groupIndex) => {
if (!notes.groupCounts[groupIndex] || !notes.items[index]) return;
return (
<Note index={index} pinnable={true} item={notes.items[index]} />
)
}
);
}}
/>
</ListContainer>
);