CopyButton
Copies given text to clipboard
Import
Source
Docs
Package
Usage
CopyButton
is based on use-clipboard hook.
Its children is a function that receives an object with the following properties:
copied
– boolean value that indicates that a given value was recently copied to the clipboard, it resets after a given timeout (defaults to 500ms)copy
– function that should be called to copy given value to clipboard
Security
Due to security reasons CopyButton
component will not work in iframes and may not work with local files opened with file://
protocol
(component will work fine with local websites that are using http://
protocol). You can learn more about navigator.clipboard
here.
Timeout
You can provide a custom copied
reset timeout
:
Incompatible with server components
CopyButton
is not compatible with React server components as it requires function as children. To use CopyButton
add "use client;"
at the top of the file.