I am kind of stumped on this simple issue! I want to simply take my form data, validate it, submit it and submit a post request to the Express API. But before that, I don't think I have a thorough understanding of how to accomplish this. I looked at this question and these and bunch of others but I am not sure this is the best approach.
This is how I assume it will be undertaken:
I create a React Component for the sign up page. (Simplified for demonstration)
class SignupForm extends Component {
constructor(props){
super(props);
this.onSubmit = this.onSubmit.bind(this);
}
onSubmit(val){
debugger;
}
render(){
return (
<form onSUbmit={ (e)=> this.onSubmit(e) }>
<input type="text" />
<label></label>
<button type="submit">Submit</button>
</form>
)
}
}
When button is clicked the OnSubmit() function triggers, where it will be passed JSON data.
{
"name": "Kanye",
"surname": "West",
"email":"yeezy@goodmusic.com",
"password":"notsurehowthiswillwork"
}
Where I can trigger my action
SignupAction()
which will make an AJAX call to my API and then update my reducers.
The confusion multiplies when it comes to using libraries like react-redux-form or redux-form. I just want to simply have a model or something for name
, surname
email
and password
, but I feel that these libraries are over-engineered as soon as they start having their own reducer like:
const store = createStore(combineForms({
user: initialUser,
}));
MY OTHER OPTION IS:
class SignupForm extends Component {
constructor(props){
super(props);
this.state.form = {
name : '',
surname: '',
email: '',
password: ''
}
}
onSubmit(e){
e.preventDefault();
this.props.SignupAction(this.state.form);
// then reset the state agian to ''
}
}
But, my question is... will this effect performance and if so WHY?