From f4cc284fb5955894e5cfe7fdb73722c569ac0132 Mon Sep 17 00:00:00 2001 From: Muhammad Eko Date: Tue, 1 Oct 2024 15:26:45 +0700 Subject: [PATCH] progress --- src/app/dashboard/turnover/page.tsx | 3 ++- src/lib/hooks.ts | 21 --------------------- src/lib/hooks/dimension.ts | 0 3 files changed, 2 insertions(+), 22 deletions(-) create mode 100644 src/lib/hooks/dimension.ts diff --git a/src/app/dashboard/turnover/page.tsx b/src/app/dashboard/turnover/page.tsx index 3820722..3f39f0b 100644 --- a/src/app/dashboard/turnover/page.tsx +++ b/src/app/dashboard/turnover/page.tsx @@ -1,5 +1,6 @@ "use client" -import { useAppSelector, useDimensions } from "@/lib/hooks"; +import { useAppSelector } from "@/lib/hooks"; +import { useDimensions } from "@/lib/hooks/dimension"; import { useGetResignCategoryQuery, useGetResignReasonQuery, useGetResignSummaryQuery, useGetResignTypeQuery } from "@/services/api"; import { BarChart, pieArcLabelClasses, PieChart } from "@mui/x-charts"; import { ChartsNoDataOverlay } from "@mui/x-charts/ChartsOverlay"; diff --git a/src/lib/hooks.ts b/src/lib/hooks.ts index 18b5b9d..157c31f 100644 --- a/src/lib/hooks.ts +++ b/src/lib/hooks.ts @@ -6,24 +6,3 @@ export const useAppDispatch = useDispatch.withTypes() export const useAppSelector = useSelector.withTypes() export const useAppStore = useStore.withTypes() -import { RefObject, useMemo, useSyncExternalStore } from "react" - -function subscribe(callback: (e: Event) => void) { - window.addEventListener("resize", callback) - return () => { - window.removeEventListener("resize", callback) - } -} - -function useDimensions(ref: RefObject) { - const dimensions = useSyncExternalStore( - subscribe, - () => JSON.stringify({ - width: ref.current?.offsetWidth ?? 0, - height: ref.current?.offsetHeight ?? 0, - }) - ) - return useMemo(() => JSON.parse(dimensions), [dimensions]) -} - -export { useDimensions } \ No newline at end of file diff --git a/src/lib/hooks/dimension.ts b/src/lib/hooks/dimension.ts new file mode 100644 index 0000000..e69de29