stargaze-studio/utils/clipboard.ts
2022-12-13 22:21:05 +03:00

12 lines
370 B
TypeScript

import type { Renderable } from 'react-hot-toast'
import { toast } from 'react-hot-toast'
export async function copy(text: string, message: Renderable = 'Copied to clipboard!') {
try {
await navigator.clipboard.writeText(text)
return toast.success(message)
} catch (err: unknown) {
return toast.error(String(err), { style: { maxWidth: 'none' } })
}
}