mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: simpler logic for resize observer
This commit is contained in:
parent
b2150b9212
commit
6c433f1f17
1 changed files with 11 additions and 12 deletions
|
|
@ -30,18 +30,17 @@ export function SizeObserver({ type = 'div', children, ...rest }: Props) {
|
|||
}, [])
|
||||
|
||||
React.useEffect(() => {
|
||||
if (features.resize) {
|
||||
const observer = new window.ResizeObserver(entries => {
|
||||
const entry = entries[0]
|
||||
if (!entry) return
|
||||
const rect = entry.contentRect
|
||||
safeSetSize(rect)
|
||||
})
|
||||
|
||||
if (ref.current) observer.observe(ref.current)
|
||||
return () => observer.disconnect()
|
||||
} else {
|
||||
if (ref.current) {
|
||||
if (ref.current) {
|
||||
if (features.resize) {
|
||||
const observer = new window.ResizeObserver(entries => {
|
||||
const entry = entries[0]
|
||||
if (!entry) return
|
||||
const rect = entry.contentRect
|
||||
safeSetSize(rect)
|
||||
})
|
||||
observer.observe(ref.current)
|
||||
return () => observer.disconnect()
|
||||
} else {
|
||||
if ('getBoundingClientRect' in ref.current) {
|
||||
const rect = ref.current.getBoundingClientRect()
|
||||
setSize(rect)
|
||||
|
|
|
|||
Loading…
Reference in a new issue