Skip to content

Instantly share code, notes, and snippets.

@converge
Created January 6, 2019 17:23
Show Gist options
  • Save converge/d5b2ddb243d08f364cbfed6f75497b08 to your computer and use it in GitHub Desktop.
Save converge/d5b2ddb243d08f364cbfed6f75497b08 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { Formik, Field, Form, ErrorMessage } from 'formik'
import './index.css'
class LoginForm extends Component {
handleSubmit = (values, actions) => {
actions.setSubmitting(true)
console.log(values)
console.log(actions)
// just login now without passwd:
const { history } = this.props
history.push('/dashboard')
}
render() {
return (
<div>
<h1>Admin</h1>
<Formik
initialValues={{
user: '',
passwd: '',
}}
validate={values => {
let errors = {}
}}
onSubmit={this.handleSubmit}
render={x => (
<div className='login-form'>
<Form>
<div className='login-item'>
<Field name='user' type='text' placeholder='Username' />
</div>
<div className='login-item'>
<Field name='passwd' type='password' placeholder='Password' />
</div>
<div className='login-item'>
<button type='submit' disabled={x.isSubmitting}>Login</button>
</div>
</Form>
</div>
)}
/>
</div>
)
}
}
export default LoginForm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment