From 593e5c1e5572ad8f62241d5827ab1e0edf86d9fc Mon Sep 17 00:00:00 2001 From: rutik wankhade Date: Thu, 26 Jan 2023 11:59:11 +0530 Subject: [PATCH] feat: add loading state for better ux --- src/components/ComponentToImg.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/ComponentToImg.js b/src/components/ComponentToImg.js index 3d3959c..38f90e1 100644 --- a/src/components/ComponentToImg.js +++ b/src/components/ComponentToImg.js @@ -1,4 +1,4 @@ -import React, { useContext } from "react"; +import React, { useContext, useState } from "react"; // import { exportComponentAsPNG } from "react-component-export-image"; import "./CoverImage.css"; import { ImgContext } from "../utils/ImgContext"; @@ -7,6 +7,8 @@ import domtoimage from "dom-to-image"; const ComponentToImg = (props) => { + const [loading, setLoading] = useState(false) + const { unsplashImage } = useContext(ImgContext); const componentRef = React.createRef(); @@ -18,12 +20,15 @@ const ComponentToImg = (props) => { a.href = data; a.download = `cover.png`; document.body.appendChild(a); + setLoading(false) + a.click(); document.body.removeChild(a); } const downloadImage = async () => { // exportComponentAsPNG(componentRef, 'cover') + setLoading(true) const element = componentRef.current; @@ -57,7 +62,17 @@ const ComponentToImg = (props) => {