screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [text, setText] = useState("Clicking Save allows you to store the content within a textarea into a text file. This action captures the texts current state, preserving it for future reference or sharing.Its a common feature in text editors, word processors, or web applications, enabling users to safeguard their input and access it later. "); const handleTextareaChange = (e) => { setText(e.target.value); }; const handleSaveToFile = () => { const blob = new Blob([text], { type: 'text/plain' }); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'text-file.txt'; a.click(); window.URL.revokeObjectURL(url); }; return ( <div className='container'> <h3 className='title'>React Js Save Textarea Value To Text File</h3> <textarea className='text-area' value={text} onChange={handleTextareaChange} rows={10} cols={40} placeholder="Enter text here..." /> <br /> <button className='save-button' onClick={handleSaveToFile}>Save to File</button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 600px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } .title { font-size: 24px; margin-bottom: 20px; } .text-area { width: 100%; height: 200px; margin-bottom: 20px; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; } .save-button { background-color: #4caf50; color: white; padding: 10px 20px; font-size: 18px; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } .save-button:hover { background-color: #45a049; } </style> </body> </html>