'react typescript image resizing and download

I was implement image resize and image download. But I see an error in 73line..

https://codesandbox.io/s/serene-monad-sc6imu?file=/src/App.tsx

I see an reference, but I can't solve the problem...



Solution 1:[1]

To solve your issue, change the declaration of the cardRef to:

const cardRef = useRef<HTMLDivElement | null>(null);

You should also remove the casting (const card = cardRef.current as any;) and modify it as follows:

const onDownloadBtn = () => {
    if(cardRef.current){
      const card = cardRef.current;
      domtoimage.toBlob(card).then((blob) => {
        saveAs(blob, "card.png");
      });
    } 
  };

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1