Files
spacedrive/interface/hooks/useScrolled.tsx
Vítor Vasconcellos 7cd0556f15 [ENG-1928] Update to tauri 2.0.1 stable (#2752)
* Update to tauri 2.0.0 stable
 - Update a some othe dependencies
 - Autoformat rust and toml files

* Fix clippy complain

* Update tauri 2.0.1
 - Update rspc
 - Update some frontend files due changes in rspc
 - Update some frontend build dependencies

* Revert babel update

* Fix code typing typing and style + a couple of bugs

* More type fixes
2024-10-05 21:17:30 +00:00

25 lines
566 B
TypeScript

import { useEffect, useState } from 'react';
export const useScrolled = (ref: React.RefObject<HTMLDivElement>, y = 1) => {
const [isScrolled, setIsScrolled] = useState(false);
useEffect(() => {
const onScroll = () => {
if (ref.current) {
if (ref.current.scrollTop >= y) setIsScrolled(true);
else setIsScrolled(false);
}
};
onScroll();
const { current } = ref;
if (current) {
current.addEventListener('scroll', onScroll);
return () => current.removeEventListener('scroll', onScroll);
}
}, [ref, y]);
return { isScrolled };
};