upd: announcement
Deskripsi: - pagination scrooll load No Issues
This commit is contained in:
38
src/module/_global/components/scroll_provider.tsx
Normal file
38
src/module/_global/components/scroll_provider.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
"use client";
|
||||
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Box } from "@mantine/core";
|
||||
import { currentScroll } from "../bin/val_global";
|
||||
|
||||
export function ScrollProvider({ children }: { children: React.ReactNode }) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const { set } = useHookstate(currentScroll);
|
||||
|
||||
useEffect(() => {
|
||||
if (window) {
|
||||
const handleScroll = () => {
|
||||
if (containerRef.current) {
|
||||
set(containerRef);
|
||||
}
|
||||
};
|
||||
|
||||
const container = containerRef.current;
|
||||
container?.addEventListener("scroll", handleScroll);
|
||||
|
||||
return () => {
|
||||
container?.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
}
|
||||
}, [containerRef, set]);
|
||||
return (
|
||||
<Box
|
||||
h={"100vh"}
|
||||
style={{ overflow: "auto", position: "relative" }}
|
||||
ref={containerRef}
|
||||
>
|
||||
{children}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user