Notoriously Psychedelic Modules

    react-copy-text

    1.0.1 • Public • Published

    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.

    Install

    npm i react-copy-text

    DownloadsWeekly Downloads

    181

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • alanshaw