feat(admin,admin-ui,medusa): Add Medusa Admin plugin (#3334)
This commit is contained in:
committed by
GitHub
parent
d6b1ad1ccd
commit
40de54b010
30
packages/admin-ui/ui/src/hooks/use-observe-width.ts
Normal file
30
packages/admin-ui/ui/src/hooks/use-observe-width.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { MutableRefObject, useEffect, useRef, useState } from "react"
|
||||
|
||||
export const useObserveWidth = (ref: MutableRefObject<any>): number => {
|
||||
const [currentWidth, setCurrentWidth] = useState(0)
|
||||
|
||||
const observer = useRef(
|
||||
new ResizeObserver((entries) => {
|
||||
const { width } = entries[0].contentRect
|
||||
|
||||
setCurrentWidth(width)
|
||||
})
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
const currentRef = ref.current
|
||||
const currentObserver = observer.current
|
||||
|
||||
if (currentRef && currentObserver) {
|
||||
currentObserver.observe(currentRef)
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (currentObserver && currentRef) {
|
||||
currentObserver.unobserve(currentRef)
|
||||
}
|
||||
}
|
||||
}, [ref, observer])
|
||||
|
||||
return currentWidth
|
||||
}
|
||||
Reference in New Issue
Block a user