useRef initial state

This commit is contained in:
James Barnsley
2024-01-03 21:34:33 +13:00
parent 35e1eb2966
commit 6f6ad998b0

View File

@ -17,15 +17,15 @@ const LyricsScroller = ({
content = '',
percent = 0,
}) => {
const containerRef = useRef({});
const contentRef = useRef({});
const containerRef = useRef(null);
const contentRef = useRef(null);
const [autoScroll, setAutoScroll] = useState(true);
const onWheel = () => setAutoScroll(false);
useEffect(() => {
if (autoScroll) {
const scrollable = contentRef.current?.scrollHeight - containerRef.current.clientHeight;
containerRef.current.scrollTo(0, percent * scrollable)
const height = (contentRef.current?.scrollHeight - containerRef.current?.clientHeight) || 0;
containerRef.current.scrollTo(0, percent * height)
}
}, [percent]);