import React from 'react'; import { useCallback, useRef, FunctionComponent, useEffect } from 'react'; import { useVirtual } from '@ishikawa_masashi/react-virtual'; import './HorizontalList.css'; type Props = { height: number; width: number; size: number; onRender: (index: number) => JSX.Element; offset: number; lineHeight: number; overscan?: number; paddingEnd?: number; }; export const HorizontalList: FunctionComponent = (props) => { const { height, width, size, onRender, offset, lineHeight, overscan = 5, paddingEnd = 0, } = props; const parentRef = useRef(null); const columnVirtualizer = useVirtual({ horizontal: true, size, parentRef, estimateSize: useCallback(() => lineHeight, [lineHeight]), overscan, paddingEnd, }); return (
{columnVirtualizer.virtualItems.map((virtualColumn) => (
{onRender(virtualColumn.index)}
))}
); };