react-copy-text
v1.0.1
Published
Copy text to the clipboard like it's 1999
Downloads
370
Maintainers
Readme
react-copy-text
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.