mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
16 lines
346 B
TypeScript
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
|
|
}
|