Skip to content

Instantly share code, notes, and snippets.

@YKalashnikov
Created July 4, 2019 00:53
Show Gist options
  • Save YKalashnikov/cb9bef7ba526cb16c4a560789277fe72 to your computer and use it in GitHub Desktop.
Save YKalashnikov/cb9bef7ba526cb16c4a560789277fe72 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {userLoginFetch} from '../redux/actions';
class Login extends Component {
state = {
username: "",
password: ""
}
handleChange = event => {
this.setState({
[event.target.name]: event.target.value
});
}
handleSubmit = event => {
event.preventDefault()
this.props.userLoginFetch(this.state)
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<h1>Login</h1>
<label>Username</label>
<input
name='username'
placeholder='Username'
value={this.state.username}
onChange={this.handleChange}
/><br/>
<label>Password</label>
<input
type='password'
name='password'
placeholder='Password'
value={this.state.password}
onChange={this.handleChange}
/><br/>
<input type='submit'/>
</form>
)
}
}
const mapDispatchToProps = dispatch => ({
userLoginFetch: userInfo => dispatch(userLoginFetch(userInfo))
})
export default connect(null, mapDispatchToProps)(Login);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment