Skip to content

Commit

Permalink
refactor: extract copy helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ogonkov committed Dec 25, 2024
1 parent 45dce74 commit 6f1539a
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/components/CopyToClipboard/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ export function CopyToClipboard(props: CopyToClipboardProps) {
(event) => {
textRef.current = text;

function copy(result: boolean) {
if (text === textRef.current) {
handleCopy(text, result);

content.props?.onClick?.(event);
}
}

copyText(text).then(
() => {
if (text === textRef.current) {
handleCopy(text, true);

if (typeof content.props?.onClick === 'function') {
content.props.onClick(event);
}
}
copy(true);
},
() => {
if (text === textRef.current) {
handleCopy(text, false);

if (typeof content.props?.onClick === 'function') {
content.props.onClick(event);
}
}
copy(false);
},
);
},
Expand Down

0 comments on commit 6f1539a

Please sign in to comment.