-
-
Save sorahn/6fac9f4717a81c96cd97e2bcc86a184f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setState | |
import React from 'react' | |
class MyForm extends React.Component { | |
constructor (props) { | |
super(props) | |
this.state = { | |
email: '', | |
password: '', | |
submitting: false, | |
} | |
} | |
render () { | |
return ( | |
<form onSubmit={(e) => { | |
e.preventDefault() | |
// Do something with this.state | |
}}> | |
<input type='email' value={this.state.email} onChange={(e) => this.setState({ email: e.target.value})} /> | |
<input type='password' value={this.state.password} onChange={(e) => this.setState({ password: e.target.value})} /> | |
<button type='submit' disabled={this.state.submitting}>Login</button> | |
</form> | |
) | |
} | |
} | |
// redux-form | |
import React from 'react' | |
import { reduxForm } from 'redux-form' | |
const MyForm = (props) => ( | |
<form onSubmit={this.props.handleSubmit(({email, password}) => { | |
// Do something with email and password. | |
})}> | |
<input type='email' {...this.props.email} /> | |
<input type='password' {...this.props.password} /> | |
<button type='submit' disabled={this.props.submitting}>Login</button> | |
</form> | |
) | |
const formConfig = { | |
form: 'login', | |
fields: ['email', 'password'], | |
} | |
export default reduxForm(formConfig)(MyForm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment