Skip to content

Commit

Permalink
error handling added to helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
dhavalveera committed Jun 3, 2024
1 parent b7c3792 commit bd1dc36
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/ui/src/components/Clipboard/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import type { Dispatch, SetStateAction } from "react";

export const copyToClipboard = (valueToCopy: string, setIsJustCopied: Dispatch<SetStateAction<boolean>>) => {
setIsJustCopied(true);
navigator?.clipboard?.writeText(valueToCopy);
navigator?.clipboard
?.writeText(valueToCopy)
.then(() => {
console.log("Copy Successfull");
})
.catch((error) => {
console.error("Failed to Copy text: ", error);
setIsJustCopied(false);
});
setTimeout(() => setIsJustCopied(false), 4000);
};

0 comments on commit bd1dc36

Please sign in to comment.