Skip to content

Instantly share code, notes, and snippets.

@wwwhatley
Last active July 14, 2018 21:46
Show Gist options
  • Save wwwhatley/c04531e31b7ca6f7ec9c974e3454bb51 to your computer and use it in GitHub Desktop.
Save wwwhatley/c04531e31b7ca6f7ec9c974e3454bb51 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
import styled from "styled-components";
import { Formik } from "formik";
import { Form, Input, Title, Text, Button, Label } from "./theme.js";
class App extends Component {
render() {
return (
<div>
<Title>Form</Title>
{/* FORMIK */}
<Formik
initialValues={{ email: "", password: "" }}
validate={values => {
console.log(values);
}}
onSubmit={values => {
console.log(values);
}}
render={({
touched,
errors,
values,
handleChange,
handleBlur,
handleSubmit
}) => (
<Form onSubmit={handleSubmit}>
<Label>
Email *
{errors.email && <Text color="red">{errors.email}</Text>}
<Input
border={errors.email && "1px solid red"}
type="text"
name="email"
placeholder="Email"
/>
</Label>
<Label>
Password *
{errors.password && <Text color="red">{errors.password}</Text>}
<Input
border={errors.password && "1px solid red"}
type="password"
name="password"
placeholder="Password"
/>
</Label>
<Button type="submit">Submit</Button>
</Form>
)}
/>
{/* END OF FORMIK */}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment