Add `useClipboard` hook
See original GitHub issueMotivation
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:
- Try using the new Clipboard API by default
- Fallback to
document.execCommand()
if necessary
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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
use-clipboard-hook - npm
use-clipboard -hook. TypeScript icon, indicating that this package has built-in type declarations. 1.1.1 • Public • Published 2 years ago.
Read more >danoc/react-use-clipboard - GitHub
React hook that provides copy to clipboard functionality. - GitHub - danoc/react-use-clipboard: React hook that provides copy to clipboard functionality.
Read more >How to Create a Custom useCopyToClipboard React Hook
A user just hovers over the snippet, clicks the clipboard button, and the code is added to their computer's clipboard to enable them...
Read more >Use-clipboard-hook NPM | npm.io
Install. Using npm: npm install --save use-clipboard-hook. Using yarn: yarn add use-clipboard-hook. Usage. import * as React from "react"; ...
Read more >useCopyToClipboard() react hook - usehooks-ts
This React hook provides a copy method to save a string in the clipboard and the copied value (default: null ). If anything...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@maciekgrzybek I would appreciate if you could take the challenge of implementation!
Ok thanks, @kripod, I’ll investigate it.