MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / useScrolledToBottom

Function useScrolledToBottom

src/components/navs/Sidebar.jsx:71–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69};
70
71const useScrolledToBottom = ref => {
72 const [isScrolledToBottom, setIsScrolledToBottom] = useState(false);
73
74 useEffect(() => {
75 const el = ref.current;
76 if (!el) return;
77
78 const handleScroll = () => {
79 const { scrollTop, scrollHeight, clientHeight } = el;
80 setIsScrolledToBottom(scrollTop + clientHeight >= scrollHeight - 10);
81 };
82
83 el.addEventListener('scroll', handleScroll);
84 handleScroll();
85 return () => el.removeEventListener('scroll', handleScroll);
86 }, [ref]);
87
88 return isScrolledToBottom;
89};
90
91// ─── Sub-components ──────────────────────────────────────────────────────────
92const ActiveLine = ({ position, isVisible }) => (

Callers 1

SidebarFunction · 0.85

Calls 1

handleScrollFunction · 0.70

Tested by

no test coverage detected