useCopyToClipboard
Copies a given text to the clipboard.
Overview
This hook manages a state copied
that indicates whether text has been recently copied to the clipboard.
It provides a function copyText
that can be used to initiate copying of text.
The copied
state automatically resets to false after a specified delay.
Code
The function attempts to copy a provided string to the system clipboard
TheReact hook that provides clipboard copying functionality
API
Parameters
resetDelay - The delay in milliseconds after which the copied
state is reset to false.
Return
A tuple containing:
- copied - A boolean value that indicates whether text has been recently copied to the clipboard.
- copyText - A function that can be used to initiate copying of text.