Last active
April 8, 2023 17:34
-
-
Save JenniferFuBook/bd811e89e12d342e62c4ff2badc5ab5e 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
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