init
This commit is contained in:
commit
a04776256d
56 changed files with 6808 additions and 0 deletions
32
lib/hooks/use-copy-to-cliipboard.tsx
Normal file
32
lib/hooks/use-copy-to-cliipboard.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
'use client';
|
||||
import { useState } from 'react';
|
||||
|
||||
export interface useCopyToClipboardProps {
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export function useCopyToClipboard({
|
||||
timeout = 2000,
|
||||
}: useCopyToClipboardProps) {
|
||||
const [isCopied, setIsCopied] = useState<Boolean>(false);
|
||||
|
||||
const copyToClipboard = (value: string) => {
|
||||
if (
|
||||
typeof window === 'undefined' ||
|
||||
!navigator.clipboard ||
|
||||
!navigator.clipboard.writeText
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
navigator.clipboard.writeText(value).then(() => {
|
||||
setIsCopied(true);
|
||||
|
||||
setTimeout(() => {
|
||||
setIsCopied(false);
|
||||
}, timeout);
|
||||
});
|
||||
};
|
||||
|
||||
return { isCopied, copyToClipboard };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue