Skip to content

tableflip/react-copy-text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-copy-text

Build Status dependencies Status JavaScript Style Guide

Copy text to the clipboard like it's 1999

Beautifully simples React component to copy the text you give to it, with optional onCopied callback so you know when it's done.

Install

npm install react-copy-text

Usage

import React, { Component } from 'react'
import CopyText from 'react-copy-text'

export default class App extends Component {
  state = {textToCopy: ''}

  onButtonClick = () => this.setState({ textToCopy: 'NOW: ' + Date.now() })
  onCopied = (text) => console.log(`${text} was copied to the clipboard`)

  render () {
    return (
      <div>
        <button onClick={this.onButtonClick}>Copy some text</button>
        <CopyText text={this.state.textToCopy} onCopied={this.onCopied} />
      </div>
    )
  }
}

API

<CopyText />

text

Type: PropTypes.string

The text to copy to the clipboard.

onCopied

Type: PropTypes.func

Callback function called after the text has been copied to the clipboard. Passed the text that was copied.

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw


A (╯°□°)╯︵TABLEFLIP side project.