Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获的TypeError:_this.props.onSubmit在使用redux表单时不是函数_Javascript_Reactjs_Redux Form - Fatal编程技术网

Javascript 未捕获的TypeError:_this.props.onSubmit在使用redux表单时不是函数

Javascript 未捕获的TypeError:_this.props.onSubmit在使用redux表单时不是函数,javascript,reactjs,redux-form,Javascript,Reactjs,Redux Form,我正在使用React.js前端,当我尝试登录或注册时,单击登录或注册按钮时会出现以下错误 stacktrace指向以下文件 /src/containers/Login/index.js 再次感谢您的帮助 最后,可以找到整个项目。handleSubmit是一个通过redux表单注入组件的道具,onSubmit不是。。。您必须确保自己提供,或者只需在LoginFormhandleSubmit中处理表单提交 您也可以这样做: 参考资料: 在你的App/index.js中,你做到了 在本例中,您将看到“

我正在使用React.js前端,当我尝试登录或注册时,单击登录或注册按钮时会出现以下错误

stacktrace指向以下文件

/src/containers/Login/index.js

再次感谢您的帮助

最后,可以找到整个项目。

handleSubmit是一个通过redux表单注入组件的道具,onSubmit不是。。。您必须确保自己提供,或者只需在LoginFormhandleSubmit中处理表单提交

您也可以这样做:

参考资料:

在你的App/index.js中,你做到了

在本例中,您将看到“hi”打印到dev控制台

Uncaught TypeError: _this.props.onSubmit is not a function
// @flow
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import { Link } from 'react-router-dom';
import { css, StyleSheet } from 'aphrodite';
import Input from '../../components/Input';

const styles = StyleSheet.create({
  card: {
    maxWidth: '500px',
    padding: '3rem 4rem',
    margin: '2rem auto',
  },
});

type Props = {
  onSubmit: () => void,
  handleSubmit: () => void,
  submitting: boolean,
}

class LoginForm extends Component {
  props: Props

  handleSubmit = (data) => this.props.onSubmit(data);
  // handleSubmit: (data) => this.props.onSubmit(data);


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

    return (
      <form
        className={`card ${css(styles.card)}`}
        onSubmit={handleSubmit(this.handleSubmit)}
      >
        <h3 style={{ marginBottom: '2rem', textAlign: 'center' }}>Login to Sling</h3>
        <Field name="email" type="text" component={Input} placeholder="Email" />
        <Field name="password" type="password" component={Input} placeholder="Password" />
        <button
          type="submit"
          disabled={submitting}
          className="btn btn-block btn-primary"
        >
          {submitting ? 'Logging in...' : 'Login'}
        </button>
        <hr style={{ margin: '2rem 0' }} />
        <Link to="/signup" className="btn btn-block btn-secondary">
          Create a new account
        </Link>
      </form>
    );
  }
}

const validate = (values) => {
  const errors = {};
  if (!values.email) {
    errors.email = 'Required';
  }
  if (!values.password) {
    errors.password = 'Required';
  }
  return errors;
};

export default reduxForm({
  form: 'login',
  validate,
})(LoginForm);
  handleSubmit = (data) => this.props.onSubmit(data);
 <RedirectAuthenticated path="/login" component={Login} {...authProps} /> 
// add this function
const LoginComponent = () => {
    return (
        <Login onSubmit={() => { console.log("hi") }} />
    )   
}

class App extends Component {
    ...

   render() {
     ....
     <RedirectAuthenticated path="/login" component={LoginComponent} {...authProps} />