use-clipboard
Wrapper around navigator.clipboard with feedback timeout
Usage
use-clipboard hook provides interface to work with navigator.clipboard:
No iframes
Due to security reasons use-clipboard hook will not work in iframes and may not work with local files opened with file:// protocol (hook will work fine with local websites that are using http:// protocol). You can learn more about navigator.clipboard here.
API
use-clipboard hook accepts one argument options in which copied status timeout duration is defined (defaults to 2000). Hook returns object with properties:
copy– function to copy value to clipboardcopied– value that indicates that copy handler was called less thanoptions.timeoutms agoreset– function to clear timeout and resetcopiedto falseerror– containsErrorobject if something goes wrong
Definition
function useClipboard(options: { timeout: number } = { timeout: 2000 }): {
copy: (valueToCopy: any) => void;
reset: () => void;
error: Error;
copied: boolean;
};