ai-lab-tube / src /lib /hooks /useCanvasImage.ts
jbilcke's picture
working to improve the clap format
f42b4a1
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;
}