question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `useClipboard` hook

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kripodcommented, Sep 23, 2019

@maciekgrzybek I would appreciate if you could take the challenge of implementation!

2reactions
maciekgrzybekcommented, Sep 29, 2019

Ok thanks, @kripod, I’ll investigate it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found