screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://cdn.jsdelivr.net/npm/@babel/standalone@7.14.6/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel" data-presets="env,react"> const { useRef } = React; function App() { const textAreaRef = useRef(null); const handlePaste = async () => { try { const text = await navigator.clipboard.readText(); textAreaRef.current.value = text; } catch (error) { console.error("Failed to read clipboard data:", error); } }; return ( <div className="container"> <h3>React Js Paste from Clipboard</h3> <button onClick={handlePaste}>Paste from Clipboard</button> <textarea ref={textAreaRef} rows={5} cols={50} placeholder="Paste here..." /> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> /* Container Styles */ .container { max-width: 500px; margin: 0 auto; padding: 20px; border: 1px solid #ccc; border-radius: 10px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } /* Button Styles */ button { background-color: #007bff; color: #fff; border: none; border-radius: 5px; padding: 10px 20px; cursor: pointer; font-size: 16px; transition: background-color 0.2s ease; } button:hover { background-color: #0056b3; } /* Textarea Styles */ textarea { width: 100%; padding: 10px; margin-top: 10px; resize: vertical; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; } textarea::placeholder { color: #ccc; } /* Optional: If you want to add some space below the textarea */ textarea { margin-bottom: 20px; } </style> </body> </html>