0.1.1 • Published 8 months ago

@1ohooks/use-copy-to-clipboard v0.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

@1ohooks/use-copy-to-clipboard

@1ohooks/use-copy-to-clipboard is a custom React hook that simplifies copying text to the clipboard and provides feedback when the copy operation is successful.

Installation

Install the package with:

npm install @1ohooks/use-copy-to-clipboard
# or
yarn add @1ohooks/use-copy-to-clipboard

Usage

To use the useCopyToClipboard hook in your React project, import it and provide the text you want to copy to the clipboard.

import { useCopyToClipboard } from '@1ohooks/use-copy-to-clipboard';

function MyComponent() {
  const [isCopied, copyToClipboard] = useCopyToClipboard();

  const handleCopyClick = () => {
    const textToCopy = "Hello, world!";
    copyToClipboard(textToCopy);
  };

  return (
    <div>
      <button onClick={handleCopyClick}>Copy to Clipboard</button>
      {isCopied && <p>Text copied to clipboard!</p>}
    </div>
  );
}

The useCopyToClipboard hook returns a boolean value isCopied, which indicates whether the copy operation was successful, and a function copyToClipboard to trigger the copy operation.

The isCopied state is set to true when the text is successfully copied to the clipboard and automatically resets after 1.5 seconds to provide user feedback.

Requirements

  • React 16 or higher.

Contributing

We welcome contributions from the open-source community to improve and enhance @1ohooks/use-copy-to-clipboard. If you have ideas for improvements, new features, or bug fixes, please check out our Contributing Guidelines for more information on how to contribute.

License

@1ohooks/use-copy-to-clipboard is licensed under the MIT License. You are free to use, modify, and distribute it in your projects. We appreciate attribution but do not require it.

Thank you for using @1ohooks/use-copy-to-clipboard to simplify copying text to the clipboard in your React applications. We hope you find it useful!

0.1.1

8 months ago

0.1.0

8 months ago