import _ from "lodash";
import {
InputHTMLAttributes,
memo,
ReactNode,
useCallback,
useEffect,
useRef,
} from "react";
let interval: ReturnType | null = null;
export const AnimatedHeight = memo(
(props: { children: ReactNode } & InputHTMLAttributes) => {
const el = useRef(null);
const updateSize = useCallback(() => {
if (el.current) {
const contentHeight = el.current.scrollHeight;
const parent = el.current.parentNode as HTMLDivElement;
parent.style.height = `${contentHeight}px`;
parent.style.overflow = `hidden`;
}
}, [el]);
useEffect(() => {
interval = setInterval(() => {
updateSize();
}, 200);
return () => {
if (interval)
clearInterval(interval);
};
}, []);
return (
);
}
);