0

I need to create a button that, when I click on it, I copy a specific link I'm using react.js

This is my button in moment

<a href="#"
 className="group inline-flex items-center font-medium text-indigo-600 hover:text-indigo-900">
 <LinkIcon 
   className="h-5 w-5 text-indigo-500 group-hover:text-indigo-900"
   aria-hidden="true"/>
  <span className="ml-2">Copy link</span>
</a>

enter image description here

When I click on this button, I need the clipboard to have something like this "https::/google.com"

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Julia Cassemiro
  • 89
  • 1
  • 10

3 Answers3

1

You can use React copy to clip board package for that. This is easy to use. Follow the below link.

https://www.npmjs.com/package/react-copy-to-clipboard

Comment here if you still face any issue.

0

You just need this function:

const writeTextToClipboard = text => navigator.clipboard.writeText(text);

Just place the function at the onclick event with the text link you need to copy

Nacho
  • 870
  • 6
  • 9
0

You can try this if you're using hooks.

Tarun
  • 104
  • 4