useOnResize
A hook that triggers a callback function when the specified element or the window is resized.
Usage
import { useOnResize } from '@w3ux/hooks';
...
// Ref for the element we are watching for resize.
const outerElement = useRef<HTMLDivElement>(null);
// Define the callback function.
const onResize = () => {
console.log('This logic will execute when the provided element resizes.');
};
// Execute callback function on `outerElement` resize, and provide
// an optional throttle in milliseconds.
useOnResize(() => onResize, {
outerElement,
throttle: 200,
});