UNPKG

@replyke/ui-core-react-js

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

25 lines 758 B
import { useEffect, useRef, useState } from "react"; function useWidth() { const [width, setWidth] = useState(0); const ref = useRef(null); useEffect(() => { const handleResize = (entries) => { if (entries[0].contentRect) { setWidth(entries[0].contentRect.width); } }; const resizeObserver = new ResizeObserver(handleResize); const currentRef = ref.current; if (currentRef) { resizeObserver.observe(currentRef); } return () => { if (currentRef) { resizeObserver.unobserve(currentRef); } }; }, []); return [width, ref]; } export default useWidth; //# sourceMappingURL=useWidth.js.map