Motivation
When it comes to interacting with the clipboard, multiple options are available. The Clipboard API is not yet widely supported by browsers.
A compatible solution should be available out of the box:
Basic example
function Example() {
const { copy, cut, paste } = useClipboard();
const [value, setValue] = useState('foo');
return (
<>
<input value={value} onChange={(e) => setValue(e.target.value)} />
<button type="button" onClick={() => copy(value)}>Copy</button>
</>
);
}
Details
Lack of permissions (e.g. for pasting) should be handled gracefully with opt-in support for error callbacks.
Motivation
When it comes to interacting with the clipboard, multiple options are available. The Clipboard API is not yet widely supported by browsers.
A compatible solution should be available out of the box:
document.execCommand()if necessaryBasic example
Details
Lack of permissions (e.g. for pasting) should be handled gracefully with opt-in support for error callbacks.