Last active
January 27, 2020 01:34
-
-
Save JenniferFuBook/d05d06b397dbd2f7827184c816648025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
value: 'highlight and copy me' | |
} | |
this.textInput = React.createRef(); | |
console.log(this.textInput); | |
this.handleClick = this.handleClick.bind(this); | |
} | |
handleClick() { | |
console.log(this.textInput.current); | |
this.textInput.current.select(); | |
document.execCommand('copy'); | |
} | |
render() { | |
return ( | |
<div> | |
<input type="text" ref={this.textInput} readOnly value={this.state.value}/> | |
<button onClick={this.handleClick}>Copy</button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment