Home > OS >  Button with copyable link
Button with copyable link

Time:10-07

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"

CodePudding user response:

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.

CodePudding user response:

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

CodePudding user response:

You can try this if you're using hooks.

  • Related