Created
March 9, 2024 00:03
-
-
Save cheskoxd/ee09cedeb8579f3668aa10425cd1147c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
export const useClipboard = () => { | |
const [isCopied, setIsCopied] = useState(false); | |
const copyToClipboard = (text: string) => { | |
navigator.clipboard.writeText(text).then( | |
() => setIsCopied(true), | |
() => setIsCopied(false) | |
); | |
}; | |
return [isCopied, copyToClipboard] as const; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment