logoReact Modern Hooks

Documentation

Getting Started

Installation

Hooks Overview

useFetch( )useCopyToClipboard( )useNetwork( )useFullScreen( )useGeolocation( )useSelectedText( )useStateCallback( )useResize( )useSearch( )useImageDownload( )

useCopyToClipboard( )

A React Hook that allows copying of text to clipboad. Providing the capability to copy text from one medium to another. The hook provides a copyText method which can be used to copy the text

Usage

1import { useCopyToClipboard } from 'react-modern-hooks'
2
3const Demo = () => {
4 const { copiedText, copyText, error, copied } = useCopyToClipboard()
5
6 console.log('is text copied', copied)
7
8 return (
9 <div>
10 {error ? <p>Error copying text: {error}</p> : null}
11
12 <button onClick={() => copyText('Copy this text to clipboard')}>
13 Copy Text to clipboard
14 </button>
15 </div>
16 )
17}
18
19export default Demo

References

Input Variables

No input variables

Output Variables

error - Error message that occured during copy

copied - Boolean state if the text was copied successfully

copiedText - The copied text

copyText - A function to copy the text