Skip to content

Commit

Permalink
feat(useResizeObserver): support box option (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraS authored Jul 2, 2024
1 parent 4a087e1 commit a178dff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/hooks/useResizeObserver/useResizeObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import React from 'react';
interface UseResizeObserverProps<T> {
ref: React.RefObject<T | null | undefined> | undefined;
onResize: () => void;
box?: ResizeObserverBoxOptions;
}

export function useResizeObserver<T extends Element>({ref, onResize}: UseResizeObserverProps<T>) {
export function useResizeObserver<T extends Element>({
ref,
onResize,
box,
}: UseResizeObserverProps<T>) {
React.useEffect(() => {
const element = ref?.current;
if (!element) {
Expand All @@ -26,9 +31,9 @@ export function useResizeObserver<T extends Element>({ref, onResize}: UseResizeO
onResize();
});

observer.observe(element);
observer.observe(element, {box});
return () => {
observer.disconnect();
};
}, [ref, onResize]);
}, [ref, onResize, box]);
}

0 comments on commit a178dff

Please sign in to comment.