0.0.2 ā€¢ Published 5 years ago

use-copy v0.0.2

Weekly downloads
168
License
MIT
Repository
github
Last release
5 years ago

useCopy šŸ“‹

A React Hook that provides an easy interface to copy textual data.

import React from 'react';
import useCopy from 'use-copy';

function Count() {
   const [copied, copy, setCopied] = useCopy("Text to copy");

   const copyText = () => {
     copy();

     setTimeout(() => {
       setCopied(false);
     }, 3000);
   };

   return (
       <div>
           { copied ? "Copied to clipboard" : <a onClick={copyText}>Copy text</a> }
       </div>
   );
}

Full example on Code Sandbox

Install

# Yarn
yarn add use-copy

# NPM
npm install use-copy

Features

  • Feather light
  • Pass dynamic text
  • Easy interface
  • Full Typescript support
  • Uses the battle-tested copy-to-clipboard

Prerequisites

āš ļø React hooks require react at version 16.7.0-alpha.0 or higher.

Issues & suggestions

If you find any runtime issues or have any suggestions on how to improve the package please do open an issue!

License

MIT License