Uncaught TypeError: this.props.signinUser is not a function (...)

Src / action / index.js

import axios from 'axios';
const ROOT_URL = "http://localhost:3090";

export function signinUser({ email, password }){
    return function(dispatch){
        axios.post(`${ROOT_URL}/signin`, { email, password });
        console.log("hey");
    }
} 

Src / components / authentication

import React, { Component } from 'react';
import { reduxForm } from 'redux-form';
import * as actions from '../../actions';
class Signin extends Component {


    handleFormSubmit({ email, password }){
            this.props.signinUser({ email, password });

        }

    render() {
        // code
        console.log(actions)
        const { handleSubmit, fields: { email,password } } = this.props;
        return (
        <form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
            <fieldset className="form-group">
                <label>Email:</label>
                <input {...email} className="form-control" />
            </fieldset>
            <fieldset className="form-group">
                <label>Password:</label>
                <input {...password} className="form-control" />
            </fieldset>
            <button action="submit" className="btn btn-primary">Sign In</button>

        </form>
    );
    }

    // methods
}

export default reduxForm({
    form: 'signin',
    fields: ['email',  'password']
}, null, actions)(Signin);

I am using a Redux form to create an iconic form. This is the error that I get when I click the "Login" button. The signinUser () function may not be properly defined.

bundle.js: 29019 Uncaught TypeError: this.props.signinUser is not a function (...)

+3
source share
4 answers

, - ( Udemy), redux-form 5.x 6. , reducexForm , https://github.com/erikras/redux-form/issues/1050#issuecomment-221721848.

:

Sigin = reduxForm({ form: 'sigin', fields: [ 'email', 'password' ] })(Sigin);
export default connect(null, actions)(Sigin);
+13

github , , v6.5.0 . Stephen Grider Advanced React Redux Udemy. , .

:

Redux Form v6 . fieldset Field :

import { reduxForm, Field } from 'redux-form';

, :

import { connect } from 'react-redux';

:

const renderInput = field => {
    const { input, type } = field;
    return (
        <div>
            <input {...input} type={type} className="form-control" />
        </div>
    );
}

class Signin extends Component {
    handleFormSubmit({ email, password }) {    
        this.props.signinUser({ email, password });
    }

    render(){
        const { handleSubmit } = this.props;

        return (
            <form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>

                <div className="form-group">
                    <label>Email:</label>
                    <Field name="email" 
                        type="email" component={renderInput} />
                </div>
                <div className="form-group">
                    <label>Password:</label>
                    <Field name="password" 
                        type="password" component={renderInput} />
                </div>
                <button action="submit" className="btn btn-primary">Sign in</button>
            </form>
        );
    }
}

function mapStateToProps(state) {
    return { form: state.form };
}

Signin = connect(mapStateToProps, actions)(Signin);
Signin = reduxForm({
 form: 'signin'
})(Signin);
export default Signin;

Redux Form , .

+5

actions.signinUser({ email, password });

+2

redux-form 5.3.3

+1

Source: https://habr.com/ru/post/1658943/


All Articles