Manage system clipboard with useClipboard
The useClipboard hook provides a reactive interface to the Web Clipboard API. It allows you to asynchronously read from and write to the system clipboard. Access is subject to the Permissions API; without user permission, reading or altering clipboard contents is not permitted.
Returned values:
text: A reactive store containing the current clipboard content.isSupported: A reactive store indicating if the browser supports the Clipboard API.copy: A function used to write a string to the clipboard.
To support browsers that do not implement the Clipboard API, set the legacy: true option to enable document.execCommand as a fallback.
import { useClipboard } from 'sveltuse';
const { text, isSupported, copy } = useClipboard();
// To copy text:
copy('Hello World');
// To use legacy fallback:
const { copy } = useClipboard({ legacy: true });