Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (21 sloc) 785 Bytes
import { useRef, useEffect } from 'react';
import useResizeObserver from './use-resize-observer';
export default function useAnimateHeight() {
const wrapperRef = useRef<HTMLDivElement>(null);
const [elRef, commentsListDimensions] = useResizeObserver<
HTMLAnchorElement
>();
useEffect(() => {
if (elRef.current && wrapperRef.current) {
wrapperRef.current.style.height =
elRef.current.getBoundingClientRect().height + 'px';
}
}, [commentsListDimensions, elRef, wrapperRef]);
useEffect(() => {
if (wrapperRef.current) {
wrapperRef.current.style.transition = 'height 0.5s ease-out';
wrapperRef.current.style.overflow = 'hidden';
}
}, [wrapperRef]);
return [wrapperRef, (elRef as any) as React.RefObject<HTMLDivElement>];
}
You can’t perform that action at this time.