stargaze-studio/utils/clipboard.ts
2022-07-13 16:56:36 +03:00

12 lines
353 B
TypeScript

import { toast } from 'react-hot-toast'
import type { Renderable } from 'react-hot-toast/dist/core/types'
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))
}
}