Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { connect } from 'react-redux';
- import ListErrors from './ListErrors';
- import agent from '../agent';
- // extract data from auth reducer
- const mapStateToProps = state => ({ ...state.auth });
- const mapDispatchToProps = dispatch => ({
- // update form values => reducer puts values into state => redux puts state into props and we re-render
- onChangeEmail: value =>
- dispatch({ type: 'UPDATE_FIELD_AUTH', key: 'email', value }),
- onChangePassword: value =>
- dispatch({ type: 'UPDATE_FIELD_AUTH', key: 'password', value }),
- // action with login request
- onSubmit: (email, password) =>
- dispatch({ type: 'LOGIN', payload: agent.Auth.login(email, password) })
- });
- class Login extends React.Component {
- constructor() {
- super();
- this.changeEmail = event => this.props.onChangeEmail(event.target.value);
- this.changePassword = event => this.props.onChangePassword(event.target.value);
- this.submitForm = (email, password) => event => {
- event.preventDefault();
- this.props.onSubmit(email, password);
- };
- }
- // ...
Advertisement
Add Comment
Please, Sign In to add comment