Skip to content

Instantly share code, notes, and snippets.

@curran
curran / useWidthDetector.js
Last active April 11, 2021 23:27 — forked from AdamMcCormick/ScrollBarAdapter.jsx
A hook to listen for width changes or scroll-bar show/hide.
import { useEffect } from 'react';
/**
* A hook to listen for width changes or scroll-bar show/hide.
*
* Arguments:
* * containerRef - a React ref to the element whose width you want to measure.
* * onWidthChanged - a function that is invoked when the width changes.
*
* Based on https://gist.github.com/AdamMcCormick/d5f718d2e9569acdf7def25e8266bb2a