Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Last active January 27, 2020 01:34
Show Gist options
  • Save JenniferFuBook/d05d06b397dbd2f7827184c816648025 to your computer and use it in GitHub Desktop.
Save JenniferFuBook/d05d06b397dbd2f7827184c816648025 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.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