Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Last active January 27, 2020 03:40
Show Gist options
  • Save JenniferFuBook/b2451799a9cb8b791fb33bfdcc58ec60 to your computer and use it in GitHub Desktop.
Save JenniferFuBook/b2451799a9cb8b791fb33bfdcc58ec60 to your computer and use it in GitHub Desktop.
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