This commit is contained in:
Muhammad Eko 2024-10-01 15:26:45 +07:00
parent 560e8dade1
commit f4cc284fb5
3 changed files with 2 additions and 22 deletions

View File

@ -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";

View File

@ -6,24 +6,3 @@ export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()
export const useAppStore = useStore.withTypes<AppStore>()
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<HTMLElement>) {
const dimensions = useSyncExternalStore(
subscribe,
() => JSON.stringify({
width: ref.current?.offsetWidth ?? 0,
height: ref.current?.offsetHeight ?? 0,
})
)
return useMemo(() => JSON.parse(dimensions), [dimensions])
}
export { useDimensions }

View File