|
| 1 | +import React,{useState} from 'react'; |
| 2 | + |
| 3 | +const Register = () => { |
| 4 | + |
| 5 | + const [info,setInfo] = useState({name:"",email:"",password:"",error:"",loading:false,message:"",showForm:true}); |
| 6 | + |
| 7 | + const {name,email,password,error,loading,message,showForm} = info |
| 8 | + |
| 9 | + const handleSubmit=(event)=>{ |
| 10 | + event.preventDefault(); |
| 11 | + console.table({name,email,password,error,loading,message,showForm}) |
| 12 | + } |
| 13 | + |
| 14 | + const handleChange= name =>(event)=>{ |
| 15 | + setInfo({...info,error:false,[name]: e.target.value}); |
| 16 | + } |
| 17 | + const registerForm=()=>{ |
| 18 | + return ( |
| 19 | + <form onSubmit={handleSubmit}> |
| 20 | + {/* Name */} |
| 21 | + <div className="form-group"> |
| 22 | + {/* dynamic handle change by passing the value straight to it */} |
| 23 | + <input type="text" value={name} className="form-control" onChange={handleChange("name")} placeholder="Enter Your Name"/> |
| 24 | + </div> |
| 25 | + {/* Email */} |
| 26 | + <div className="form-group"> |
| 27 | + <input type="email" value={email} className="form-control" onChange={handleChange("email")} placeholder="Enter Your @Email address"/> |
| 28 | + </div> |
| 29 | + {/* Password */} |
| 30 | + <div className="form-group"> |
| 31 | + <input type="password" value={password} className="form-control" onChange={handleChange("password")} placeholder="Enter Your password"/> |
| 32 | + </div> |
| 33 | + <button className="btn btn-info">Register</button> |
| 34 | + </form> |
| 35 | + ) |
| 36 | +} |
| 37 | + return ( |
| 38 | + <> |
| 39 | + {registerForm()} |
| 40 | + </> |
| 41 | + ) |
| 42 | +} |
| 43 | + |
| 44 | +export default Register |
0 commit comments