Last active
January 27, 2020 03:40
-
-
Save JenniferFuBook/b2451799a9cb8b791fb33bfdcc58ec60 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 MyTextInput = (props) => { | |
return ( | |
<input {...props}/> | |
); | |
}; | |
const App = () => { | |
const [value, setValue] = React.useState('highlight and copy me'); | |
const textInput = React.useRef('initialRef'); | |
const handleClick = () => { | |
console.log(textInput.current); | |
textInput.current.select(); | |
document.execCommand('copy'); | |
} | |
return ( | |
<div> | |
<MyTextInput 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