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.
npm install react-copy-text
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>
)
}
}
Type: PropTypes.string
The text to copy to the clipboard.
Type: PropTypes.func
Callback function called after the text has been copied to the clipboard. Passed the text that was copied.
Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw
A (╯°□°)╯︵TABLEFLIP side project.