Files
formbricks-formbricks/packages/lib/utils/hooks/useSyncScroll.ts
Dhruwang Jariwala 00beeb0501 fix: recall parsing in emails and improvements in response pipeline (#2187)
Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
Co-authored-by: Shubham Palriwala <spalriwalau@gmail.com>
2024-03-21 13:03:13 +00:00

27 lines
793 B
TypeScript

import { RefObject, useEffect } from "react";
// Custom hook to synchronize the horizontal scroll position of two elements.
export const useSyncScroll = (
highlightContainerRef: RefObject<HTMLElement>,
inputRef: RefObject<HTMLElement>
): void => {
useEffect(() => {
const syncScrollPosition = () => {
if (highlightContainerRef.current && inputRef.current) {
highlightContainerRef.current.scrollLeft = inputRef.current.scrollLeft;
}
};
const sourceElement = inputRef.current;
if (sourceElement) {
sourceElement.addEventListener("scroll", syncScrollPosition);
}
return () => {
if (sourceElement) {
sourceElement.removeEventListener("scroll", syncScrollPosition);
}
};
}, [inputRef, highlightContainerRef]);
};