Skip to content

useResizeObserver ​

browser
test coverage
Last changed: 24 days ago

TIP

This hook uses ResizeObserver browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api

Hook that gives you resize observer state

typescript
import { useResizeObserver } from '@siberiacancode/reactuse';

Usage ​

typescript
const { ref, entries } = useResizeObserver();
// or
const { entries } = useResizeObserver(ref);

Demo ​

Api ​

Parameters

NameTypeDefaultNote
options.enabled?booleantrueThe IntersectionObserver options
options.box?boolean-The IntersectionObserver options
options.onChange?(entries: ResizeObserverEntry[], observer: ResizeObserver) => void-The callback to execute when resize is detected

Parameters

NameTypeDefaultNote
targetHookTarget-The target element to observe
options.enabled?booleantrueThe IntersectionObserver options
options.box?boolean-The IntersectionObserver options
options.onChange?(entries: ResizeObserverEntry[], observer: ResizeObserver) => void-The callback to execute when resize is detected

Source ​

Source • Demo

Contributors ​

Avatardebabin

Released under the MIT License.