fix: "ResizeObserver loop limit exceeded"

This commit is contained in:
EnixCoda 2019-08-12 20:59:49 +08:00
parent 0cdb49414a
commit 5ea59c3d5f
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -27,13 +27,17 @@ export default function SizeObserver({
const entry = entries[0]
if (!entry) return
const rect = entry.contentRect
setSize({
width: rect.width,
height: rect.height,
})
// requestAnimationFrame fixes "ResizeObserver loop limit exceeded" error
requestAnimationFrame(() =>
setSize({
width: rect.width,
height: rect.height,
}),
)
})
if (ref.current) observer.observe(ref.current)
return () => observer.disconnect()
}, [])
const props: any = { ...rest, ref } // :)