mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-28 18:38:12 -04:00
* 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
25 lines
566 B
TypeScript
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 };
|
|
};
|