Files
linsa-linsa-io/web/shared/minimal-tiptap/hooks/use-image-load.ts
2024-10-07 12:44:17 +03:00

16 lines
346 B
TypeScript

import * as React from "react"
export const useImageLoad = (src: string) => {
const [imgSize, setImgSize] = React.useState({ width: 0, height: 0 })
React.useEffect(() => {
const img = new Image()
img.src = src
img.onload = () => {
setImgSize({ width: img.width, height: img.height })
}
}, [src])
return imgSize
}