From 60d8c2cc932aa53763d6d481c21a3a03e48abdef Mon Sep 17 00:00:00 2001 From: checktheroads Date: Mon, 8 Feb 2021 16:08:46 -0700 Subject: [PATCH] fix handling of codeBlock copy value --- components/codeBlock/codeBlock.tsx | 10 +++++++++- components/codeBlock/types.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/components/codeBlock/codeBlock.tsx b/components/codeBlock/codeBlock.tsx index f9ba1276..c41fd00d 100644 --- a/components/codeBlock/codeBlock.tsx +++ b/components/codeBlock/codeBlock.tsx @@ -35,7 +35,15 @@ export const CodeBlock: React.FC = (props: ICodeBlock) => { colorScheme: ctx.copyButton.colorScheme, variant: 'ghost', }); - const { hasCopied, onCopy } = useClipboard(children); + + let copyValue = ''; + if (typeof children === 'string') { + copyValue = children; + } else { + copyValue = children.props.children; + } + + const { hasCopied, onCopy } = useClipboard(copyValue); return (