chukwuyem

Untitled

Oct 16th, 2020
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component, useState} from 'react';
  2. import { connect } from 'react-redux'
  3. import { loginUsers } from '../redux'
  4.  
  5.  
  6.  
  7.  
  8.  
  9. class LoginUser extends Component {
  10.    
  11.  
  12.  
  13.     handleChange = e => {
  14.         this.setState({
  15.           [e.target.name]: e.target.value
  16.         });
  17.       }
  18.    
  19.    
  20.      submitHandler = e => {
  21.       //const {email_id, password_id} = useState('');
  22.      
  23.  
  24.        e.preventDefault();
  25.        let {email_id, password_id} = this.state
  26.        try{
  27.         console.log('done', email_id, password_id);
  28.        this.props.loginUsers(email_id, password_id);
  29.        
  30.  
  31.        }catch(error){
  32.          console.log(error)
  33.          
  34.  
  35.        }
  36.        
  37.      
  38.      }
  39.     render() {
  40.       //const {title, body} = this.state
  41.      // const { password_id, email_id, } = this.props;
  42.  
  43.       return (
  44.         <div>
  45.             <h2>
  46.                 Number of cake - {this.props.email_id}
  47.             </h2>
  48.          
  49.           <form onSubmit={this.submitHandler}>
  50.             <label>
  51.               Person Name:
  52.               <input type="text" name="email_id"  onChange={this.handleChange} />
  53.             </label>
  54.             <label>
  55.               Person Name:
  56.               <input type="text" name="password_id"  onChange={this.handleChange} />
  57.             </label>
  58.             <button type="submit" >Add</button>
  59.           </form>
  60.           <div>{this.errors}</div>
  61.         </div>
  62.       )
  63.     }
  64.   }
  65.  
  66.  
  67.    
  68.  
  69. const mapStateToProps = state => {
  70.     return {
  71.         users: state.auth,
  72.        
  73.        
  74.     }
  75. }
  76.  
  77. const mapDispatchToProps = dispatch => {
  78.     return {
  79.       loginUsers: (email, pass, ) => dispatch(loginUsers( {email, pass}))
  80.     }
  81.   }
  82.  
  83. export default
  84. connect(mapStateToProps,mapDispatchToProps)(LoginUser)
RAW Paste Data