未捕获的TypeError:this.props.signinUser不是函数(...) [英] Uncaught TypeError: this.props.signinUser is not a function(…)
问题描述
src / actions / 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 / auth
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);
我正在使用Redux表格登录表格。这是我点击登录按钮时出现的错误。也许signinUser()函数没有正确定义。
I am using Redux Form to make a sign in form. This is the error I get when I Click on the 'Sign in' button. Maybe the signinUser() function is not properly defined.
bundle.js:29019 Uncaught TypeError:this.props.signinUser不是函数(...)
bundle.js:29019 Uncaught TypeError: this.props.signinUser is not a function(…)
推荐答案
如果有人遇到它(我现在对Udemy做同样的啧啧),这是redux-form 5.x和6之间的一个重大变化。基本上,你只需要通过reduxForm运行并连接,如本评论所示 https:// github .com / erikras / redux-form / issues / 1050#issuecomment-221721848 。
In case anyone runs into it (I'm doing the same tut on Udemy now), this was a breaking change between redux-form 5.x and 6. Basically, you just have to run it through reduxForm and connect, as shown in this comment https://github.com/erikras/redux-form/issues/1050#issuecomment-221721848.
最终结果如下:
Sigin = reduxForm({ form: 'sigin', fields: [ 'email', 'password' ] })(Sigin);
export default connect(null, actions)(Sigin);
这篇关于未捕获的TypeError:this.props.signinUser不是函数(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!