From 583c30d76fa499097897399aa0c5ecadbf0a5e03 Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Thu, 14 Nov 2024 05:18:52 -0800 Subject: [PATCH] Strict type useResizeObserver --- .../desktop-client/src/hooks/useResizeObserver.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/desktop-client/src/hooks/useResizeObserver.ts b/packages/desktop-client/src/hooks/useResizeObserver.ts index 4137dd92524..58573eff5d5 100644 --- a/packages/desktop-client/src/hooks/useResizeObserver.ts +++ b/packages/desktop-client/src/hooks/useResizeObserver.ts @@ -1,20 +1,19 @@ -// @ts-strict-ignore import { useRef, useCallback } from 'react'; -export function useResizeObserver( +export function useResizeObserver( func: (contentRect: DOMRectReadOnly) => void, -): (el: unknown) => void { - const observer = useRef(null); +): (el: T) => void { + const observer = useRef(undefined); if (!observer.current) { observer.current = new ResizeObserver(entries => { func(entries[0].contentRect); }); } - const elementRef = useCallback(el => { - observer.current.disconnect(); + const elementRef = useCallback((el: T) => { + observer.current?.disconnect(); if (el) { - observer.current.observe(el, { box: 'border-box' }); + observer.current?.observe(el, { box: 'border-box' }); } }, []);