mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-18 23:36:00 +00:00
- Mobile responsive - new toast design - web document render issue fix - posthog analytics - ui improvements
23 lines
515 B
TypeScript
23 lines
515 B
TypeScript
import { useEffect, useState } from "react"
|
|
|
|
export default function useResizeObserver<T extends HTMLElement>(
|
|
ref: React.RefObject<T | null>,
|
|
) {
|
|
const [size, setSize] = useState({ width: 0, height: 0 })
|
|
|
|
useEffect(() => {
|
|
if (!ref.current) return
|
|
|
|
const observer = new ResizeObserver(([entry]) => {
|
|
setSize({
|
|
width: entry?.contentRect.width ?? 0,
|
|
height: entry?.contentRect.height ?? 0,
|
|
})
|
|
})
|
|
|
|
observer.observe(ref.current)
|
|
return () => observer.disconnect()
|
|
}, [ref])
|
|
|
|
return size
|
|
}
|