Saya mencoba melakukan otorisasi. Saya mendapatkan data dari reduxForm, dan itu terlihat, tetapi untuk beberapa alasan data tidak langsung masuk ke fungsi, tetapi beraksi, dan saya mendapatkan nilai yang tidak ditentukan. Pendaftaran dilakukan dengan prinsip yang sama, tetapi tidak ada kesalahan.

Di mana kesalahan saya?

REDUX

const NewUserEror = "NewUserEror";
const RegSucces = "RegSucces";
const RegStart = "RegStart";
const RegEnd = "RegEnd";

let initialState = {
  error: null,
  loading: false
};

const registrationReducer = (state = initialState, action) => {
  switch (action.type) {
    case RegSucces:
      return {
        ...state,
        error: false
      };
    case NewUserEror:
      return {
        ...state,
        error: action.payload
      };
    case RegStart:
      return {
        ...state,
        loading: true
      };
    case RegEnd:
      return {
        ...state,
        loading: false
      };

    default:
      return state;
  }
};
export const LogInUser = data => async (
  dispatch,
  getState,
  { getFirebase }
) => {
  const firebase = getFirebase();
  dispatch({ type: RegStart });
  try {
    await firebase.auth().signInWithEmailAndPassword(data.email, data.password);
    dispatch({ type: RegSucces });
  } catch (err) {
    dispatch({ type: NewUserEror, payload: err.message });
  }
  dispatch({ type: RegEnd });
};


CONTAINER

import React from "react";
import { connect } from "react-redux";
import Login from "./login";
import LogInUser from "./../../../redux/registrationReducer"
class AuthBox extends React.Component{

  Userlogin=(formdata)=>{

    this.props.LogInUser(formdata)
  }
  render(){
    return<Login {...this.props} Userlogin={this.Userlogin}></Login>
  }
}

let mapStateToProps=(state)=>{
  return{
  loading:state.Regis.loading,
  error:state.Regis.error
  }
}



export default connect(mapStateToProps,{LogInUser})(AuthBox);



COMPONENT

const Login = props => {
  let onSubmit = formData => {
  props.Userlogin(formData);
  };
  return (
    <div className={classes.formbox}>
      <div className={classes.form}>
        <h5 className={classes.formtitle}>Вход</h5>
        <LoginForm onSubmit={onSubmit}></LoginForm>
      </div>
    </div>
  );
};

export default Login;

Kesalahan

Tindakan tidak terdefinisi

P.s maaf untuk bahasa inggris saya

0
NoreChase 29 Oktober 2019, 20:19

1 menjawab

Jawaban Terbaik

EKSPOR NON DEFAULT HARUS DI {}

import React from "react";
import { connect } from "react-redux";
import Login from "./login";

////// here
import {LogInUser} from "./../../../redux/registrationReducer"
////

class AuthBox extends React.Component{

  Userlogin=(formdata)=>{

    this.props.LogInUser(formdata)
  }
  render(){
    return<Login {...this.props} Userlogin={this.Userlogin}></Login>
  }
}

let mapStateToProps=(state)=>{
  return{
  loading:state.Regis.loading,
  error:state.Regis.error
  }
}



export default connect(mapStateToProps,{LogInUser})(AuthBox);
1
NoreChase 29 Oktober 2019, 21:08