UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

29 lines (28 loc) 1.09 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useIsComponentMountedRef } from '@selfcommunity/react-core'; import useResizeObserver from 'use-resize-observer'; /** * A wrapper component for children of * VirtualScroll. Computes current height and * update virtual scroll. */ const VirtualScrollChild = ({ children, onHeightChange }) => { // REFS const isMountedRef = useIsComponentMountedRef(); /** * Use useResizeObserver to intercept layout change: * onResize callback function, receive the width and height of the * element when it changes and call onHeightChange * It does not cover all possible cases, so all elements that can be * included in the feed must implement the interface VirtualScrollerItemProps */ const { ref } = useResizeObserver({ onResize: ({ width, height }) => { if (isMountedRef.current) { onHeightChange && onHeightChange(); } } }); return _jsx("div", Object.assign({ ref: ref }, { children: children })); }; export default VirtualScrollChild;