Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Created January 27, 2020 01:46
Show Gist options
  • Save JenniferFuBook/29e2f2b01c61ab89b7d89282b5658f0f to your computer and use it in GitHub Desktop.
Save JenniferFuBook/29e2f2b01c61ab89b7d89282b5658f0f to your computer and use it in GitHub Desktop.
const App = () => {
const [value, setValue] = React.useState('highlight and copy me');
const textInput = React.useRef();
const handleClick = () => {
textInput.current.select();
document.execCommand('copy');
}
return (
<div>
<input type="text" ref={textInput} readOnly value={value}/>
<button onClick={handleClick}>Copy</button>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment