Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Jun 19, 2017
1 parent df0e225 commit 22ed7d0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions example/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import * as React from 'react';
import * as yup from 'yup';

import Formik, { InjectedFormikProps } from 'formik';
import Formik, { FormikBag, InjectedFormikProps } from 'formik';

export interface FormProps {
export interface Props {
email: string;
firstName: string;
social: {
facebook: string;
};
}

interface FormValues {
interface Values {
email: string;
firstName: string;
facebook: string;
}

interface FormPayload {
data: FormValues;
interface Payload {
data: Values;
}

const withFormik = Formik<FormProps, FormValues, FormPayload>({
const FormikEnhancer = Formik<Props, Values, Payload>({
mapPropsToValues: ({ email, firstName, social }) => ({
email,
firstName,
Expand All @@ -33,7 +33,10 @@ const withFormik = Formik<FormProps, FormValues, FormPayload>({
firstName: yup.string().min(5).required(),
facebook: yup.string(),
}),
handleSubmit: (payload, { props, setSubmitting }) => {
handleSubmit: (
payload: Payload,
{ setSubmitting }: FormikBag<Props, Values>
) => {
callMyApi(payload).then(
res => {
setSubmitting(false);
Expand All @@ -55,7 +58,7 @@ function MyForm({
handleSubmit,
values: { email, firstName, facebook },
handleChange,
}: InjectedFormikProps<FormValues>) {
}: InjectedFormikProps<Props, Values>) {
return (
<form onSubmit={handleSubmit}>
<input
Expand Down Expand Up @@ -84,4 +87,4 @@ function MyForm({
);
}

export default withFormik(MyForm);
export default FormikEnhancer(MyForm);

0 comments on commit 22ed7d0

Please sign in to comment.