mirror of
https://github.com/remvze/moodist.git
synced 2026-03-10 05:53:13 +08:00
20 lines
413 B
TypeScript
20 lines
413 B
TypeScript
import { useState, useCallback } from 'react';
|
|
|
|
export function useCopy(timeout = 1500) {
|
|
const [copying, setCopying] = useState(false);
|
|
|
|
const copy = useCallback(
|
|
(content: string) => {
|
|
if (copying) return;
|
|
|
|
navigator.clipboard.writeText(content);
|
|
setCopying(true);
|
|
|
|
setTimeout(() => setCopying(false), timeout);
|
|
},
|
|
[copying, timeout],
|
|
);
|
|
|
|
return { copy, copying };
|
|
}
|