Skip to content

Commit

Permalink
fix: incorrect copied state useClipboard (#6585)
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 authored Jan 15, 2025
1 parent 7c2a6de commit 6f6f98f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/6585.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix(useClipboard): Do not have a pending promise in a boolean state @nileshgulia1
10 changes: 7 additions & 3 deletions packages/volto/src/hooks/clipboard/useClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export default function useClipboard(clipboardText = '') {
}
};

const copyAction = useCallback(() => {
const copiedString = copyToClipboard(stringToCopy.current);
setCopied(copiedString);
const copyAction = useCallback(async () => {
try {
await copyToClipboard(stringToCopy.current);
setCopied(true);
} catch (error) {
setCopied(false);
}
}, [stringToCopy]);

useEffect(() => {
Expand Down

0 comments on commit 6f6f98f

Please sign in to comment.