Skip to content

Commit

Permalink
Add Radio Group example
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Jan 28, 2020
1 parent c060d16 commit f67e217
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/radio-group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Formik Radio Group Example
39 changes: 39 additions & 0 deletions examples/radio-group/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Formik, Field, Form } from 'formik';

const Example = () => (
<div>
<h1>Sign Up</h1>
<Formik
initialValues={{
picked: '',
}}
onSubmit={async values => {
await new Promise(r => setTimeout(r, 500));
alert(JSON.stringify(values, null, 2));
}}
>
{({ values }) => (
<Form>
<div id="my-radio-group">Picked</div>
<div role="group" aria-labeledby="my-radio-group">
<label>
<Field type="radio" name="picked" value="One" />
One
</label>
<label>
<Field type="radio" name="picked" value="Two" />
Two
</label>
<div>Picked: {values.picked}</div>
</div>

<button type="submit">Submit</button>
</Form>
)}
</Formik>
</div>
);

ReactDOM.render(<Example />, document.getElementById('root'));
17 changes: 17 additions & 0 deletions examples/radio-group/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "formik-example-radio-group",
"version": "0.1.0",
"description": "This example demonstrates how to create a radio group with Formik",
"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
}
}

0 comments on commit f67e217

Please sign in to comment.