Skip to content

Instantly share code, notes, and snippets.

@sorahn
Last active June 13, 2016 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorahn/6fac9f4717a81c96cd97e2bcc86a184f to your computer and use it in GitHub Desktop.
Save sorahn/6fac9f4717a81c96cd97e2bcc86a184f to your computer and use it in GitHub Desktop.
// 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