Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Last active April 8, 2023 17:34
Show Gist options
  • Save JenniferFuBook/bd811e89e12d342e62c4ff2badc5ab5e to your computer and use it in GitHub Desktop.
Save JenniferFuBook/bd811e89e12d342e62c4ff2badc5ab5e to your computer and use it in GitHub Desktop.
const App = () => {
const [value, setValue] = React.useState('highlight and copy me');
let textInput;
const handleClick = () => {
textInput.select();
document.execCommand('copy');
}
return (
<div>
<input type="text" ref={el => textInput = el} 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