ai-clip-factory / src /lib /useCanvasImage.ts
jbilcke-hf's picture
jbilcke-hf HF staff
initial commit
9a42933
raw
history blame contribute delete
428 Bytes
import { useState, useEffect } from "react"
export function useCanvasImage(url: string): HTMLImageElement | null {
const [imageSrc, setImageSrc] = useState<HTMLImageElement | null>(null);
useEffect(() => {
const img = new Image();
img.onload = () => {
setImageSrc(img);
};
img.src = url;
return () => {
img.onload = null;
img.src = '';
};
}, [url]);
return imageSrc;
}