From b2af7a97b273eb2673a8b14f40f5237e7749baf3 Mon Sep 17 00:00:00 2001 From: p-sw Date: Mon, 3 Jun 2024 14:22:00 +0900 Subject: [PATCH] fix: add error message when LoadedCode copy is not successful --- packages/react/src/components/LoadedCode.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/react/src/components/LoadedCode.tsx b/packages/react/src/components/LoadedCode.tsx index f449046..204367c 100644 --- a/packages/react/src/components/LoadedCode.tsx +++ b/packages/react/src/components/LoadedCode.tsx @@ -37,12 +37,20 @@ export const LoadedCode = forwardRef< size="icon" className="absolute top-4 right-4 text-black dark:text-white z-10" onClick={() => { - navigator.clipboard.writeText(state ?? ""); - toast({ - title: "Copied", - description: "The code has been copied to your clipboard.", - status: "success", - }); + if (typeof state === "string" && state.length > 0) { + navigator.clipboard.writeText(state ?? ""); + toast({ + title: "Copied", + description: "The code has been copied to your clipboard.", + status: "success", + }); + } else { + toast({ + title: "Error", + description: "It seems like code is not loaded yet.", + status: "error", + }); + } }} >