From 926c2fc8516ab5b807244b4a8b33ba3d8a67ccb3 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 16 Feb 2023 14:50:55 +0800 Subject: [PATCH] fix: fix useVirtual invalid in list work with autosizer In [AutoSizer](https://github.com/bvaughn/react-virtualized/blob/master/source/AutoSizer/AutoSizer.js) The height pass to children will must be 0, and next to real height. and in List, if `height === 0`, `useVirtual` will be `false`. And virtual effect will invalid and all list item will be render. In your souce code, i think you did wanna to check whether height is a valid number, skip virtual if height not set and not a number. so i think a strict check is better than implicit type conversion. --- src/List.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/List.tsx b/src/List.tsx index 59fd1694..3684cee3 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -79,7 +79,7 @@ export function RawList(props: ListProps, ref: React.Ref) { } = props; // ================================= MISC ================================= - const useVirtual = !!(virtual !== false && height && itemHeight); + const useVirtual = !!(virtual !== false && typeof height === 'number' && itemHeight); const inVirtual = useVirtual && data && itemHeight * data.length > height; const [scrollTop, setScrollTop] = useState(0);