-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUrlCopyButton.tsx
More file actions
36 lines (32 loc) · 882 Bytes
/
UrlCopyButton.tsx
File metadata and controls
36 lines (32 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import ToastMessage from "@/components/ToastMessage";
import { useState } from "react";
const UrlCopyButton = ({ currentUrl }: { currentUrl: string }) => {
const [toastMessage, setToastMessage] = useState<string>("");
const handleCopy = () => {
navigator.clipboard
.writeText(currentUrl)
.then(() => {
setToastMessage("URL을 복사했습니다.");
})
.catch((err) => {
console.error("URL 복사 실패:", err);
});
};
return (
<>
<button
onClick={handleCopy}
className="flex h-8 items-center justify-center rounded-[20px] bg-primary-normal px-4 py-2 text-white"
>
복사
</button>
{toastMessage && (
<ToastMessage
message={toastMessage}
onClose={() => setToastMessage("")}
/>
)}
</>
);
};
export default UrlCopyButton;