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, useEffect } = React; function App() { const [formData, setFormData] = useState({ name: '', email: '' }); const handleSubmit = (event) => { const { name, email } = formData; event.preventDefault(); console.log('Name:', name); console.log('Email:', email); setFormData({ name: '', email: '' }); }; const handleInputChange = (event) => { const { id, value } = event.target; setFormData((prevData) => ({ ...prevData, [id]: value })); }; return ( <div className='container'> <h3>React get form data on submit</h3> <form onSubmit={handleSubmit}> <div> <label htmlFor="name">Name:</label> <input type="text" id="name" value={formData.name} onChange={handleInputChange} required /> </div> <div> <label htmlFor="email">Email:</label> <input type="email" id="email" value={formData.email} onChange={handleInputChange} required /> </div> <button type="submit">Submit</button> </form> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Container */ .container { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); text-align: center; } h3 { color: #333; } form { display: flex; flex-direction: column; align-items: center; } div { margin: 10px 0; } label { font-weight: bold; } input[type="text"], input[type="email"] { width: 100%; padding: 10px; margin: 5px 0; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; } button[type="submit"] { background-color: #007bff; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 18px; } button[type="submit"]:hover { background-color: #0056b3; } </style> </body> </html>