Updated sticky header logic.

This commit is contained in:
Mike Cao committed 2023-02-09 08:22:36 -08:00
1 parent 45c13da262
commit f062cdbed2
8 files changed
+31 -24

No files matched your search

+7 -1
View File
@@ -1,15 +1,21 @@
import { useEffect, useRef } from 'react';
import classNames from 'classnames';
import useSticky from 'hooks/useSticky';
export default function StickyHeader({ className, stickyClassName, stickyStyle, children }) {
const { ref, isSticky } = useSticky();
const initialWidth = useRef(0);
useEffect(() => {
initialWidth.current = ref.current.clientWidth;
}, [ref]);
return (
<div
ref={ref}
data-sticky={isSticky}
className={classNames(className, { [stickyClassName]: isSticky })}
style={isSticky ? { ...stickyStyle, width: ref?.current?.clientWidth } : null}
style={isSticky ? { ...stickyStyle, width: initialWidth.current } : null}
>
{children}
</div>