Advertisement
chukwuyem

login form

Oct 28th, 2020
2,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {useContext, useEffect, useState} from 'react';
  2. import { AuthContext } from '../context/AuthContext';
  3.  
  4. const Login = () => {
  5.    
  6.     const {LoginUsers} = useContext(AuthContext);
  7.  
  8.  
  9.     const [email, setEmail] = useState('');
  10.     const[password, setPassword] = useState('');
  11.  
  12.    
  13.  
  14.  
  15.  
  16.     // useEffect(() =>{
  17.        
  18.        
  19.     // }, [])
  20.  
  21.     // const ChangeHandler = e => {
  22.     //   this.setState({[e.target.name]: e.target.value})
  23.     // }
  24.     const handleSubmit = (e) => {
  25.       e.preventDefault();
  26.       LoginUsers(email, password)
  27.       setEmail('')
  28.       setPassword('')
  29.       //console.log(email, password);
  30.     }
  31.    
  32.    
  33.     return (
  34.      
  35.  
  36.         <div>
  37.          
  38.        
  39.         <div>
  40.         <form onSubmit={handleSubmit}>
  41.           <label>
  42.             Person Name:
  43.         <input type="text" name="email" value={email} onChange={(e) => setEmail(e.target.value)} ></input>
  44.           </label>
  45.           <label>
  46.             Person Name:
  47.       <input type="text" name="password" value={password}  onChange={(e) => setPassword(e.target.value)} ></input>
  48.           </label>
  49.           <button type="submit" >Add</button>
  50.         </form>
  51.         </div>
  52.        
  53.         </div>
  54.       )
  55. }
  56.  
  57.  
  58. export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement