reactuals
Version:
A useful package providing a collection of 50+ React hooks and utilities to simplify React development.
21 lines (20 loc) • 661 B
JavaScript
import { useCallback, useState } from "react";
export function useClipboardRead() {
const [error, setError] = useState(null);
const readText = useCallback(async () => {
try {
if (!navigator.clipboard) {
throw new Error("Clipboard API not supported");
}
const text = await navigator.clipboard.readText();
setError(null);
return text;
}
catch (err) {
const error = err instanceof Error ? err : new Error("Failed to read clipboard");
setError(error);
return null;
}
}, []);
return { readText, error };
}