Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Last active April 8, 2023 17:33
Show Gist options
  • Save JenniferFuBook/19ba0618f68f3c6fa4287a95ba641031 to your computer and use it in GitHub Desktop.
Save JenniferFuBook/19ba0618f68f3c6fa4287a95ba641031 to your computer and use it in GitHub Desktop.
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