React,React Redux,Redux表单类型无效

时间:2017-04-13 10:07:28

标签: reactjs redux react-redux

我遇到了这个问题但无法解决。

这是我的代码:

import React from 'react';
import {withRouter} from 'react-router-dom';
import {Field, reduxForm} from 'redux-form';
import {connect} from 'react-redux';

import {RenderField} from 'modules/shared/components/RenderField';


class Register extends React.Component {
    handleFormSubmit(data){
        console.log(data);
    }
    render() {
        const {handleSubmit} = this.props;
        return (
            <div className="form-popup">
                <div className="form-popup-content">
                    <h4 className="popup-title">Daftar Baru</h4>

                    <hr className="line-separator"/>

                    <form id="register-form" name="registerForm" method="POST" onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>

                        <Field name="name" type="text" component={RenderField} label="Name"/>

                        <button type="submit" id="register-button" className="button mid dark ladda-button"
                                data-style="expand-right">
                            Register
                        </button>
                    </form>
                </div>
            </div>
        );
    }
}

function mapStateToProps(state){
    return state;
}

Register = reduxForm({
    form: 'registerForm',
})(Register);
export default withRouter(connect(mapStateToProps, null))(Register);

编译,我收到了这个错误:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

任何解决方案?

1 个答案:

答案 0 :(得分:2)

(Register)应该在connect()之后。

更改

export default withRouter(connect(mapStateToProps, null))(Register);

export default withRouter(connect(mapStateToProps, null)(Register));