Skip to content

Commit c055587

Browse files
committed
docs: update readme to add snack example
1 parent 5fcbc76 commit c055587

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,40 @@ yarn add formik react-native-formik
4949

5050
## Guides
5151

52-
### The Gist
53-
54-
Say we want to create a form with Material design inputs.
52+
### The Gist [See it in Snack](https://snack.expo.io/@almouro/react-native-formik-gist)
5553

5654
#### Use any Input component
5755

58-
Let's create our custom text input design, called `MaterialTextInput`:
59-
60-
We can use [react-native-material-textfield](https://github.com/n4kz/react-native-material-textfield) for the material design.
56+
We can use any `Input` component. It will receive an `error` prop in addition to the usual `TextInput` props.
6157

62-
Our component will receive `error` in addition to the usual `TextInput` props.
63-
For `withNextInputAutoFocus` to work, the input component should be a class and implement a `focus` method.
58+
For instance, we can use [react-native-material-textfield](https://github.com/n4kz/react-native-material-textfield) for the material design.
6459

6560
#### Create our form logic
6661

6762
We can compose our input with `handleTextInput` to make it boilerplate free. It will:
6863

6964
- automatically manage its state in formik provided it has a `name` prop
70-
- automatically set its error prop if input is touched or form has been submitted
71-
- automatically
65+
- automatically set its `error` prop if input is touched or form has been submitted
66+
- automatically adds the correct `TextInput` props dependending on its type (at the moment, `email`, `password`, `digits`, `name` are supported)
7267

73-
Let's add in `withNextInputAutoFocusInput`:
68+
Let's add in `withNextInputAutoFocusInput`, which provides those awesome features:
69+
70+
- when an input is submitted, it will automatically focuses on the next or submit the form if it's the last one
71+
- sets return key to "next" or "done" if input is the last one or not
72+
For `withNextInputAutoFocus` to work, the input component should be a class and implement a `focus` method.
7473

7574
```javascript
7675
import { compose } from "recompose";
7776
import {
7877
handleTextInput,
7978
withNextInputAutoFocusInput
8079
} from "react-native-formik";
81-
import MaterialTextInput from "./MaterialTextInput";
80+
import { TextField } from "react-native-material-textfield";
8281

8382
const MyInput = compose(
8483
handleTextInput,
8584
withNextInputAutoFocusInput
86-
)(MaterialTextInput);
85+
)(TextField);
8786
```
8887

8988
To complement `withNextInputAutoFocusInput`, we need to create a `Form` component, for instance:
@@ -140,16 +139,17 @@ import { Button, TextInput, View } from "react-native";
140139
import { compose } from "recompose";
141140
import { Formik } from "formik";
142141
import * as Yup from "yup";
143-
import makeInputGreatAgain, {
142+
import {
143+
handleTextInput,
144144
withNextInputAutoFocusForm,
145145
withNextInputAutoFocusInput
146146
} from "react-native-formik";
147-
import MaterialTextInput from "./MaterialTextInput";
147+
import { TextField } from "react-native-material-textfield";
148148

149149
const MyInput = compose(
150-
makeInputGreatAgain,
150+
handleTextInput,
151151
withNextInputAutoFocusInput
152-
)(MaterialTextInput);
152+
)(TextField);
153153
const Form = withNextInputAutoFocusForm(View);
154154

155155
const validationSchema = Yup.object().shape({
@@ -182,7 +182,7 @@ export default props => (
182182

183183
Boilerplate-free, hassle-free, our form is awesome with minimum code required.
184184

185-
### Custom components
185+
### Custom components [See it in Snack](https://snack.expo.io/@almouro/react-native-formik-gist)
186186

187187
#### withFormikControl usage
188188

0 commit comments

Comments
 (0)