-
-
Save surya76657/d190d34af1f9c0b398fbb3864fc7c309 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
| function CopyButton({ value }) { | |
| let [copied, setCopied] = React.useState(); | |
| let hydrated = usePageIsHydrated(); | |
| React.useEffect(() => { | |
| let id = setTimeout(() => setCopied(false), 2000); | |
| return () => clearTimeout(id); | |
| }, [copied]); | |
| return ( | |
| <button | |
| disabled={!hydrated} | |
| onClick={() => { | |
| navigator.clipboard.writeText(value); | |
| setCopied(true); | |
| }} | |
| > | |
| <ClipboardSvgIcon /> | |
| {copied ? "Copied!" : "Copy"} | |
| </button> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment