From a178dffefb2d1cfa481417a2dea6297034ae22a0 Mon Sep 17 00:00:00 2001 From: Valerii Sidorenko Date: Tue, 2 Jul 2024 13:14:14 +0200 Subject: [PATCH] feat(useResizeObserver): support box option (#1687) --- src/hooks/useResizeObserver/useResizeObserver.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/hooks/useResizeObserver/useResizeObserver.ts b/src/hooks/useResizeObserver/useResizeObserver.ts index c95193d741..3c247768c4 100644 --- a/src/hooks/useResizeObserver/useResizeObserver.ts +++ b/src/hooks/useResizeObserver/useResizeObserver.ts @@ -3,9 +3,14 @@ import React from 'react'; interface UseResizeObserverProps { ref: React.RefObject | undefined; onResize: () => void; + box?: ResizeObserverBoxOptions; } -export function useResizeObserver({ref, onResize}: UseResizeObserverProps) { +export function useResizeObserver({ + ref, + onResize, + box, +}: UseResizeObserverProps) { React.useEffect(() => { const element = ref?.current; if (!element) { @@ -26,9 +31,9 @@ export function useResizeObserver({ref, onResize}: UseResizeO onResize(); }); - observer.observe(element); + observer.observe(element, {box}); return () => { observer.disconnect(); }; - }, [ref, onResize]); + }, [ref, onResize, box]); }