Closed andrewtremblay closed 3 years ago
Nevermind! I found out about AutoSizer, that seems to be the most common solution to this; https://github.com/bvaughn/react-window#can-a-list-or-a-grid-fill-100-the-width-or-height-of-a-page
I should have read the docs more closely.
This is what my component looks like now.
import { FixedSizeList, FixedSizeListProps } from 'react-window';
import AutoSizer, { Size } from 'react-virtualized-auto-sizer';
/** technically has both dynamic height and width */
export default function DynamicHeightFixedSizeList(
props: Partial<FixedSizeListProps>
) {
return (
<div style={{ display: 'flex', flexGrow: 1 }}>
<AutoSizer>
{({ height, width }: Size) => (
<FixedSizeList {...(props as any)} height={height} width={width} />
)}
</AutoSizer>
</div>
);
}
I often have to use a list in a full page format, but the requirement that the height needs to be provided as a number for vertical lists is slightly inconvenient.
Here's my current workaround, which allows me to consider the FixedSizeList as if it had a flexGrow of 1 by calculating the height with a dummy div:
My questions are: Does anyone have any similar approaches to this that might be better? Is there a reason why such a thing cannot be included out of the box?