Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YKalashnikov/b403986181bd820a0991de29112dd6f0 to your computer and use it in GitHub Desktop.
Save YKalashnikov/b403986181bd820a0991de29112dd6f0 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {userPostFetch} from '../redux/actions';
class Signup extends Component {
state = {
username: "",
password: "",
avatar: "",
bio: ""
}
handleChange = event => {
this.setState({
[event.target.name]: event.target.value
});
}
handleSubmit = event => {
event.preventDefault()
this.props.userPostFetch(this.state)
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<h1>Sign Up For An Account</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/>
<label>Avatar</label>
<input
name='avatar'
placeholder='Avatar (URL)'
value={this.state.avatar}
onChange={this.handleChange}
/><br/>
<label>Bio</label>
<textarea
name='bio'
placeholder='Bio'
value={this.state.bio}
onChange={this.handleChange}
/><br/>
<input type='submit'/>
</form>
)
}
}
const mapDispatchToProps = dispatch => ({
userPostFetch: userInfo => dispatch(userPostFetch(userInfo))
})
export default connect(null, mapDispatchToProps)(Signup);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment