I tried to do the copy to the clipboard feature in react js. But I am unable to do that. Here is my code
import { useEffect, useRef } from "react";
function App() {
const inputRef = useRef("");
useEffect(() => {
inputRef.current.value = window.location;
inputRef.current.select();
document.execCommand("copy");
}, []);
return (
<div className="App">
<input type="text" ref={inputRef} />
</div>
);
}
export default App;
codesandbox: https://codesandbox.io/s/gallant-tesla-6399m?file=/src/App.js:0-352
text is getting selected but it is not copying. How to fix this issue?