AllenYuan

auth - login view - state

Apr 24th, 2020
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import ListErrors from './ListErrors';
  4. import agent from '../agent';
  5.  
  6. // extract data from auth reducer
  7. const mapStateToProps = state => ({ ...state.auth });
  8.  
  9. const mapDispatchToProps = dispatch => ({
  10.   // update form values => reducer puts values into state => redux puts state into props and we re-render
  11.   onChangeEmail: value =>
  12.     dispatch({ type: 'UPDATE_FIELD_AUTH', key: 'email', value }),
  13.   onChangePassword: value =>
  14.     dispatch({ type: 'UPDATE_FIELD_AUTH', key: 'password', value }),
  15.   // action with login request
  16.   onSubmit: (email, password) =>
  17.     dispatch({ type: 'LOGIN', payload: agent.Auth.login(email, password) })
  18. });
  19.  
  20. // ...
Advertisement
Add Comment
Please, Sign In to add comment