Skip to content

allow the usage of a custom resize observer class #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function useResizeObserver<T extends HTMLElement>(
opts: {
ref?: RefObject<T> | T | null | undefined;
onResize?: ResizeHandler;
customResizeObserver?: typeof ResizeObserver;
} = {}
): HookResponse<T> {
// Saving the callback as a ref. With this, I don't need to put onResize in the
Expand Down Expand Up @@ -143,7 +144,8 @@ function useResizeObserver<T extends HTMLElement>(
// Initialising the RO instance
if (!resizeObserverRef.current) {
// Saving a single instance, used by the hook from this point on.
resizeObserverRef.current = new ResizeObserver((entries) => {
const ResizeObserverClass = opts.customResizeObserver || ResizeObserver;
resizeObserverRef.current = new ResizeObserverClass((entries) => {
if (!Array.isArray(entries)) {
return;
}
Expand Down Expand Up @@ -177,7 +179,7 @@ function useResizeObserver<T extends HTMLElement>(
});
}

resizeObserverRef.current.observe(element);
resizeObserverRef.current!.observe(element);

return () => {
if (resizeObserverRef.current) {
Expand Down