this repo has no description
at main 39 lines 1.1 kB view raw
1import { useState } from "react"; 2 3function App() { 4 const [name, setName] = useState(""); // Stores name input 5 const [email, setEmail] = useState(""); // Stores email input 6 7 function handleSubmit(event) { 8 event.preventDefault(); // Prevents page reload 9 alert(`Name: ${name}\nEmail: ${email}`); 10 // Clear the inputs after submitting 11 setName(""); 12 setEmail(""); 13 } 14 15 return ( 16 <div style={{ textAlign: "center", marginTop: "20px" }}> 17 <h2>Simple Form</h2> 18 <form onSubmit={handleSubmit}> 19 <input 20 type="text" 21 value={name} 22 onChange={(event) => setName(event.target.value)} 23 placeholder="Enter your name" 24 style={{ display: "block", margin: "10px auto", padding: "8px" }} 25 /> 26 <input 27 type="email" 28 value={email} 29 onChange={(event) => setEmail(event.target.value)} 30 placeholder="Enter your email" 31 style={{ display: "block", margin: "10px auto", padding: "8px" }} 32 /> 33 <button type="submit">Submit</button> 34 </form> 35 </div> 36 ); 37} 38 39export default App;