InputField
and Button
are custom components that go into the form to create the form. My problem is how to send the data back to the form, so that when I click the button, I can start ajax in the data form (username and password):
export default auth.authApi( class SignUpViaEmail extends Component{ constructor(props){ super(props); this.state = { email : "", password : "" }; this.storeEmail = this.storeEmail.bind( this ); this.storePassword = this.storePassword.bind( this ); } storeEmail(e){ this.setState({ email : e.target.value }); } storePassword(e){ this.setState({ password : e.target.value }); } handleSignUp(){ this.props.handleSignUp(this.state); } render(){ return( <div className="pageContainer"> <form action="" method="post"> <InputField labelClass = "label" labelText = "Username" inputId = "signUp_username" inputType = "email" inputPlaceholder = "registered email" inputClass = "input" /> <Button btnClass = "btnClass" btnLabel = "Submit" onClickEvent = { handleSignUp } /> </form> </div> ); } } );
Or is this not recommended, and I should not create custom child components in the form?
child component => InputField
import React, { Component } from "react"; export class InputField extends Component{ constructor( props ){ super( props ); this.state = { value : "" }; this.onUserInput = this.onUserInput.bind( this ); } onUserInput( e ){ this.setState({ value : e.target.value }); this.props.storeInParentState({[ this.props.inputType ] : e.target.value }); } render(){ return <div className = ""> <label htmlFor = {this.props.inputId} className = {this.props.labelClass}> {this.props.labelText} </label> <input id = {this.props.inputId} type = {this.props.inputType} onChange = {this.onUserInput} /> <span className = {this.props.validationClass}> { this.props.validationNotice } </span> </div>; } }
Error: I get an e.target is undefined
error message in the parent repository of Email func.
source share