Description
react-copy-to-clipboard is a React component that copies text to the clipboard when a user clicks its child element. It is based on the copy-to-clipboard library, and it wraps a single child, such as a button, without rendering any tag of its own, so the child is the element that captures the click. The text to copy is passed as a prop. The component calls an onCopy callback when the copy happens, with a result that is true if the copy succeeded and false otherwise. Options such as debug, message and format can be set for the copy behaviour. The README explains the fallbacks. It tries the browser's execCommand first, then the Internet Explorer clipboardData interface, and finally a simple prompt that shows the text so the user can copy it with Ctrl+C and Enter. The project has a simple web demo and a CodePen demo, and it is installed with Yarn or npm, with react as a peer dependency. It is released under the MIT licence. It suits React developers who want a copy button without writing the clipboard code themselves.…
Highlights
- Copies text on click of a child element
- onCopy callback with success result
- Fallbacks for older browsers
- Debug, message and format options
Ratings & Reviews
No ratings yet
Be the first to rate react-copy-to-clipboard.
People also visit
react-copy-to-clipboard FAQ
What does react-copy-to-clipboard do?
It copies a text prop to the clipboard when the user clicks the child element inside it.
How do I install it?
With Yarn or npm. If you use npm@3, install the react peer dependency yourself.
How do I know if the copy worked?
The onCopy callback receives a result that is true when the text was copied, and false otherwise.
What happens in browsers without clipboard support?
The component falls back from execCommand to the IE clipboardData interface, and finally shows a prompt with the text to copy by hand.
What license is it under?
MIT, according to the README.
What are the best react-copy-to-clipboard alternatives?
Popular alternatives to react-copy-to-clipboard include react-clipboard.js, react-text-truncate and react-codemirror. See all react-copy-to-clipboard alternatives




















