Last active
April 8, 2023 17:33
-
-
Save JenniferFuBook/19ba0618f68f3c6fa4287a95ba641031 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.handleClick = this.handleClick.bind(this); | |
} | |
handleClick() { | |
this.textInput.select(); | |
document.execCommand('copy'); | |
} | |
render() { | |
return ( | |
<div> | |
<input type="text" ref={el => this.textInput = el} 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