import { useCallback, useState } from "react";

export function usePasteFromClipboard() {
	const [state, setState] = useState<string>("");

	const pasteFromClipboard = useCallback(() => {
		const handlePaste = async () => {
			try {
				if (navigator?.clipboard?.readText) {
					const value = await navigator.clipboard.readText();
					setState(value);
				} else {
					throw new Error("readText not supported");
				}
			} catch (e) {
				console.log("bungee: ", e);
			}
		};

		handlePaste();
	}, []);

	return { state, pasteFromClipboard };
}
