Skip to content

Commit

Permalink
Add async submission example
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Jan 28, 2020
1 parent 7e647ad commit ce12418
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions examples/async-submission/README.md
@@ -0,0 +1,3 @@
# Formik Async Submission

[![Edit formik-example-async-submission](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/jaredpalmer/formik/tree/master/examples/async-submission?fontsize=14&hidenavigation=1&theme=dark)
12 changes: 6 additions & 6 deletions examples/AsyncSubmit.js → examples/async-submission/index.js
@@ -1,10 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Formik, Field, Form } from 'formik';
import { Debug } from './Debug';

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const sleep = ms => new Promise(r => setTimeout(r, ms));

const AsyncSubmit = () => (
const Example = () => (
<div>
<h1>Sign Up</h1>
<Formik
Expand All @@ -14,7 +14,7 @@ const AsyncSubmit = () => (
email: '',
}}
onSubmit={async values => {
await sleep(1000);
await sleep(500);
alert(JSON.stringify(values, null, 2));
}}
>
Expand All @@ -28,14 +28,14 @@ const AsyncSubmit = () => (

<label htmlFor="email">Email</label>
<Field name="email" placeholder="jane@acme.com" type="email" />

<button type="submit" disabled={isSubmitting}>
Submit
</button>
<Debug />
</Form>
)}
</Formik>
</div>
);

export default AsyncSubmit;
ReactDOM.render(<Example />, document.getElementById('root'));
17 changes: 17 additions & 0 deletions examples/async-submission/package.json
@@ -0,0 +1,17 @@
{
"name": "formik-example-async-submission",
"version": "0.1.0",
"description": "This example demonstrates how to use Formik in it's most basic way",
"main": "index.js",
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0",
"formik": "latest"
},
"prettier": {
"trailingComma": "es5",
"singleQuote": true,
"semi": true
}
}
4 changes: 3 additions & 1 deletion examples/basic-typescript/README.md
@@ -1 +1,3 @@
# Formik x TypeScript Example
# Formik TypeScript Example

[![Edit formik-example-basic-typescript](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/jaredpalmer/formik/tree/master/examples/basic-typescript?fontsize=14&hidenavigation=1&theme=dark)
2 changes: 2 additions & 0 deletions examples/basic/README.md
@@ -1 +1,3 @@
# Formik Basic Example

[![Edit formik-example-basic](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/jaredpalmer/formik/tree/master/examples/basic?fontsize=14&hidenavigation=1&theme=dark)

0 comments on commit ce12418

Please sign in to comment.