useCopyToClipboard
Alias of useClipboard.
Import
TypeScript
import { useCopyToClipboard } from '@/hooks';API
Signature
useCopyToClipboard(options?)
When to use
Use useCopyToClipboard instead of re-implementing the same pattern in multiple components.
SSR / Next.js
Browser utilities are SSR-gated; lifecycle hooks are safe.
Live playground
Edit the example and see it run against the real @/hooks package in this app.
Live playgroundEdit · run with real
@/hooks · useCopyToClipboardEditor
function Copy(props: { text: string }) { const { copy, copied } = useCopyToClipboard(); return <button onClick={() => void copy(props.text)}>{copied ? '✓' : 'Copy'}</button>; }
Preview
Implementation source
Full library source for useCopyToClipboard — copy into your project when you are not installing a package yet.
hooks/utility/useCopyToClipboard.ts
import { useClipboard, type UseClipboardOptions, type UseClipboardReturn } from './useClipboard';
export type UseCopyToClipboardReturn = UseClipboardReturn;
/** Alias of {@link useClipboard}. */
export function useCopyToClipboard(
options?: UseClipboardOptions,
): UseCopyToClipboardReturn {
return useClipboard(options);
}
Copy-paste example
useCopyToClipboard.example.tsx
'use client';
import { useCopyToClipboard } from '@/hooks';
export function Copy(props: { text: string }) {
const { copy, copied } = useCopyToClipboard();
return <button onClick={() => void copy(props.text)}>{copied ? '✓' : 'Copy'}</button>;
}Production checklist
- Called only from Client Components or other custom hooks
- Type parameters filled in (e.g.
useFetch<User[]>) - Tip: Lifecycle hooks are for side effects only — not for deriving render state.
- Source of truth: open
hooks/utility/useCopyToClipboard.tsfor implementation details