import * as React from 'react'; import { getParentScrollableElement } from '../hooks'; type WithScrollContainerProps = { children: (scrollContainer: HTMLElement) => React.ReactElement | null; }; export const WithScrollContainer: React.FC = ({ children }) => { const [scrollContainer, setScrollContainer] = React.useState(); const ref = React.useCallback((node: HTMLElement) => { if (node) { setScrollContainer(getParentScrollableElement(node)); } }, []); return scrollContainer ? children(scrollContainer) : ; };