Gathering detailed insights and metrics for @custom-react-hooks/use-clipboard
Gathering detailed insights and metrics for @custom-react-hooks/use-clipboard
Gathering detailed insights and metrics for @custom-react-hooks/use-clipboard
Gathering detailed insights and metrics for @custom-react-hooks/use-clipboard
A collection of reusable and well-documented custom React hooks for supercharging your React applications. These hooks cover a wide range of functionalities, making it easier for you to build dynamic and interactive user interfaces.
npm install @custom-react-hooks/use-clipboard
Typescript
Module System
Node Version
NPM Version
71.7
Supply Chain
100
Quality
77.5
Maintenance
100
Vulnerability
100
License
TypeScript (96.96%)
JavaScript (2.56%)
Shell (0.47%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
29,903
Last Day
154
Last Week
1,382
Last Month
5,224
Last Year
29,138
MIT License
20 Stars
36 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Feb 07, 2025
Minified
Minified + Gzipped
Latest Version
1.5.1
Package Id
@custom-react-hooks/use-clipboard@1.5.1
Unpacked Size
12.43 kB
Size
4.75 kB
File Count
8
NPM Version
10.3.0
Node Version
18.17.0
Published on
Aug 18, 2024
Cumulative downloads
Total Downloads
Last Day
-45.8%
154
Compared to previous day
Last Week
11.3%
1,382
Compared to previous week
Last Month
49.2%
5,224
Compared to previous month
Last Year
3,708.9%
29,138
Compared to previous year
1
useClipboard
HookuseClipboard
is a React hook that provides an interface for copying to and pasting from the user's clipboard. It uses the modern Clipboard API for improved performance and flexibility.
Choose and install individual hooks that suit your project needs, or install the entire collection for a full suite of utilities.
1npm install @custom-react-hooks/use-clipboard
or
1yarn add @custom-react-hooks/use-clipboard
1npm install @custom-react-hooks/all
or
1yarn add @custom-react-hooks/all
The useClipboard
hook must be imported using a named import as shown below:
Named Import:
1import { useClipboard } from '@custom-react-hooks/use-clipboard';
This approach ensures that the hook integrates seamlessly into your project, maintaining consistency and predictability in how you use our package.
1import React, { useState } from 'react'; 2import { useClipboard } from '@custom-react-hooks/use-clipboard'; 3 4const ClipboardComponent = () => { 5 const { copyToClipboard, pasteFromClipboard, state } = useClipboard(); 6 const [textToCopy, setTextToCopy] = useState(''); 7 const [pastedText, setPastedText] = useState(''); 8 9 const handleCopy = async () => { 10 await copyToClipboard(textToCopy); 11 }; 12 13 const handlePaste = async () => { 14 const text = await pasteFromClipboard(); 15 setPastedText(text); 16 }; 17 18 return ( 19 <div> 20 <input 21 type="text" 22 value={textToCopy} 23 onChange={(e) => setTextToCopy(e.target.value)} 24 placeholder="Text to copy" 25 /> 26 <button onClick={handleCopy}>Copy to Clipboard</button> 27 <button onClick={handlePaste}>Paste from Clipboard</button> 28 29 {state.success && <p>Operation successful!</p>} 30 {state.error && <p>Error: {state.error}</p>} 31 32 <p>Pasted Text: {pastedText}</p> 33 </div> 34 ); 35}; 36 37export default ClipboardComponent;
This example demonstrates how to use the useClipboard
hook to copy text to and paste text from the clipboard using buttons.
copyToClipboard(text: string)
: An asynchronous function to copy the provided text to the clipboard.pasteFromClipboard()
: An asynchronous function to paste the text from the clipboard.success
: A boolean indicating if the last operation was successful.error
: A string containing an error message if the operation failed.We encourage contributions to enhance useClipboard
. For bugs, feature requests, or pull requests, please reach out through the project's repository.
No vulnerabilities found.
No security vulnerabilities found.