Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
import { useState, useEffect, useRef } from 'react';
import ResizeObserver from '@juggle/resize-observer';
export default function useResizeObserver<T extends HTMLElement>(
predefinedRefs?: React.RefObject<T>,
): [React.RefObject<T>, DOMRectReadOnly | undefined] {
const ref = useRef<T>(null);
const [dimensions, setDimensions] = useState<DOMRectReadOnly>();
useEffect(() => {
const refToUse = predefinedRefs || ref;
if (!refToUse.current) {
const resizeObserver = new ResizeObserver(entries => {
setDimensions(entries[0].contentRect as any);
return () => {
if (refToUse.current) {
}, [(predefinedRefs || ref).current]);
return [predefinedRefs || ref, dimensions];