ai-tube / src /lib /useImageDimension.ts
jbilcke-hf's picture
jbilcke-hf HF staff
🍿
1f122c3
raw
history blame
461 Bytes
import { useEffect, useState } from "react"
import { ImageDimension, getImageDimension } from "./getImageDimension"
export function useImageDimension(src: string) {
const [dimension, setDimension] = useState<ImageDimension>({
width: 0,
height: 0,
})
useEffect(() => {
const compute = async () => {
const newDimension = await getImageDimension(src)
setDimension(newDimension)
}
compute()
}, [src])
return dimension
}