1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Always check if ref is active in virtual-list

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-06-30 15:24:24 -04:00
parent f482da0880
commit ab373e3ff8

View File

@ -75,23 +75,27 @@ export class VirtualList extends Component<Props, State> {
const { items, rowHeights } = this.props;
if (prevProps.items.length !== items.length || !isEqual(prevProps.rowHeights, rowHeights)) {
this.listRef.current.resetAfterIndex(0, false);
this.listRef.current?.resetAfterIndex(0, false);
}
}
getItemSize = (index: number) => this.props.rowHeights[index];
scrollToSelectedItem = debounce(() => {
if (!this.props.selectedItemId) return;
if (!this.props.selectedItemId) {
return;
}
const { items, selectedItemId } = this.props;
const index = items.findIndex(item => item.getId() == selectedItemId);
if (index === -1) return;
this.listRef.current.scrollToItem(index, "start");
if (index >= 0) {
this.listRef.current?.scrollToItem(index, "start");
}
});
scrollToItem = (index: number, align: Align) => {
this.listRef.current.scrollToItem(index, align);
this.listRef.current?.scrollToItem(index, align);
};
render() {