const handler = onResize({
onResize: () => console.log('resize'),
element: document.getElementById('app')!,
viewportTarget: 'any',
hasBothEvents: true, // Trace both element and viewport sizes
resizeDebounce: 100,
});
// Trigger resize with debounce
handler.debounceResize();
handler.debounceResize();
// Trigger resize without debounce
handler.resize();
// Remove listeners
handler.remove();
Adds resize event listeners to either an element (using
ResizeObserver
) or the viewport (using custom resize events). It handles debouncing and allows the removal of listeners when no longer needed. If bothelement
andhasBothEvents
are provided, bothResizeObserver
and viewport resize events will be used.