You do not receive information by email or password, because you are in console.log('this.state', this.state); state console.log('this.state', this.state); , and you did not set the status for email and password.
You now have two options:
- Set state and get form information from there
- Pass the input value to the function that processes the information
For parameter 1, you need to specify the state for your letter and password (although setting the state for the password is not recommended) and the onChange event onChange at the input (s).
Configure onChange event onChange .
<form onSubmit={ this.onFormSubmit }> <input type="text" id="email" onChange={this.handleEmailChange} value={ this.state.email } /> <input type="password" id="password" onChange={this.handlePasswordChange} value={ this.state.password } /> <button type="submit"> Login </button> </form>
And functions for setting email and password states.
handleEmailChange(event) { this.setState({ email: event.target.value }); } handlePasswordChange(event) { this.setState({ password: event.target.value }); }
And don't forget to initialize the state for email and password in the constructor and bind the functions.
constructor(props) { super(props); this.state = { email: '', password: '' }; this.handleEmailChange = this.handleEmailChange.bind(this); this.handlePasswordChange = this.handlePasswordChange.bind(this); }
And you're done! Then, in the onFormSubmit function onFormSubmit simply select the email and password values ββfrom the state of this.state.email and this.state.password and do whatever you like.
Now for option 2 you can simply enter the event.target.value inputs, these are the values ββfor the email and password, and pass these values ββto the onSubmit form event handler function, from there you can do whatever you want (set the state or update the email address and password, change them, whatever).
<form onSubmit={ this.onFormSubmit }> <input type="text" id="email" name="theEmail" /> <input type="password" id="password" name="thePassword" /> <button type="submit"> Login </button> </form>
And the onFormSubmit function.
onFormSubmit(event) { const email = event.target.theEmail.value; const password = event.target.thePassword.value;
An easier and more recommended way to accomplish what you are trying to do is option 2.
Remember, the less your application processes, the better.