Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created October 24, 2020 22:27
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanflorence/e467ceb93fdba6814ef788dcbc9f00aa to your computer and use it in GitHub Desktop.
Save ryanflorence/e467ceb93fdba6814ef788dcbc9f00aa to your computer and use it in GitHub Desktop.
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>
);
}
@osamasayed
Copy link

Do you mind sharing usePageIsHydrated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment