Created
January 27, 2020 01:46
-
-
Save JenniferFuBook/29e2f2b01c61ab89b7d89282b5658f0f to your computer and use it in GitHub Desktop.
This file contains hidden or 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'); | |
| 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