react-copy-text

Copy text to the clipboard like it's 1999

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
react-copy-text
301.0.16 years ago6 years agoMinified + gzip package size for react-copy-text in KB

Readme

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.
A (╯°□°)╯︵TABLEFLIP side project.