问题
I am getting this error message when i used a redux-form into my simple three input fields form.
form.jsx
import React, {Component} from 'react';
import { Field, reduxForm } from 'redux-form'
import { connect } from 'react-redux';
class Signup extends Component {
signupView = () => {
return (
<section id="user_login">
<form onSubmit={this.handleSignup}>
<ul>
<li>
<div className="custom_group">
<Field type="text" className="trans login_input" title="Username" name="username" placeholder="Username" />
</div>
</li>
<li className="sbt_btn">
<button className="trans white_bg">SIGN UP</button>
</li>
</ul>
</form>
</section>
)
}
render() {
return (
<div>{this.signupView()}</div>
)
}
}
const mapStateToProps = (state) => {
return {
isRegistered: state.signup.isRegistered,
};
}
const mapDispatchToProps = dispatch => ({
SingupAction: (signupInput) => { dispatch(SingupAction(signupInput)) },
})
const formWrapped = reduxForm({
form: 'Signup'
})(Signup);
export default connect(mapStateToProps, mapDispatchToProps)(formWrapped);
P.S The SingupAction
and handleSignup
is already working so i have not include them in the code.
And has already defined a Provider store
in index.js
file.
回答1:
You haven't specified the required component
property of your Field
, it should be:
<Field
type="text"
className="trans login_input"
title="Username"
name="username"
placeholder="Username"
component="input"
/>
Check here for docs
回答2:
I think you are incorrectly connecting your component to redux
, try this, Ref
Signup = connect(
mapStateToProps,
mapDispatchToProps
)(Signup);
export default reduxForm({
form: 'Signup'
})(Signup);
来源:https://stackoverflow.com/questions/56053997/check-the-render-method-of-connectedfield