fixed code

This commit is contained in:
SlimusMinus
2026-08-11 00:24:07 +03:00
parent c50b75eece
commit 7f59ee1f38
95 changed files with 3623 additions and 2830 deletions

View File

@@ -0,0 +1,27 @@
import { useRef, useCallback } from "react";
/**
* Универсальный хук для бесконечного скролла через IntersectionObserver.
* Возвращает ref, который нужно повесить на сентинел-элемент в конце списка.
*
* @param {Function} onIntersect — вызывается, когда сентинел попадает в вьюпорт
* @param {boolean} enabled — можно ли сейчас триггерить подгрузку
*/
export function useInfiniteScroll(onIntersect, enabled) {
const observerRef = useRef(null);
const sentinelRef = useCallback(node => {
if (!enabled) return;
if (observerRef.current) observerRef.current.disconnect();
observerRef.current = new IntersectionObserver(entries => {
if (entries[0].isIntersecting && enabled) {
onIntersect();
}
}, { rootMargin: "200px" });
if (node) observerRef.current.observe(node);
}, [enabled, onIntersect]);
return sentinelRef;
}