Skip to content

Instantly share code, notes, and snippets.

@cheskoxd
Created March 9, 2024 00:03
Show Gist options
  • Save cheskoxd/ee09cedeb8579f3668aa10425cd1147c to your computer and use it in GitHub Desktop.
Save cheskoxd/ee09cedeb8579f3668aa10425cd1147c to your computer and use it in GitHub Desktop.
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