UNPKG

@selfcommunity/react-ui

Version:

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

32 lines (31 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_core_1 = require("@selfcommunity/react-core"); const use_resize_observer_1 = tslib_1.__importDefault(require("use-resize-observer")); /** * A wrapper component for children of * VirtualScroll. Computes current height and * update virtual scroll. */ const VirtualScrollChild = ({ children, onHeightChange }) => { // REFS const isMountedRef = (0, react_core_1.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 } = (0, use_resize_observer_1.default)({ onResize: ({ width, height }) => { if (isMountedRef.current) { onHeightChange && onHeightChange(); } } }); return (0, jsx_runtime_1.jsx)("div", Object.assign({ ref: ref }, { children: children })); }; exports.default = VirtualScrollChild;