Skip to main content
100%

A hook to listen for width changes or scroll-bar show/hide.

✓ Published0🌍 Public
CCurran Kelleher
Last edited Jul 22, 2019
Created on Jul 22, 2019

This example demonstrates a React hook that detects when a container’s width changes, such as when scroll bars appear or disappear. It shows how to trigger a callback on width resizes without relying on the window’s resize event. The hook creates a hidden iframe element styled to span the full container width, then listens for its `contentWindow`’s `resize` event. The initial width is captured immediately, and the listener is cleaned up on unmount. The code uses React’s `useEffect` and `useRef` APIs directly.

AI-generated description

Similar vizzes