Created
October 9, 2018 07:06
-
-
Save macouella/c24297564e2b750e2cc1feacb0bffbb4 to your computer and use it in GitHub Desktop.
For Simon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { StyleSheet, View, Button, TextInput } from "react-native"; | |
import { Formik, Field } from "formik"; | |
const MyTextInput = ({ field, ...props }) => { | |
console.log(field, props); | |
return ( | |
<TextInput | |
value={field.value} | |
onChangeText={props.form.handleChange(field.name)} | |
onBlur={props.form.handleBlur(field.name)} | |
style={{ height: 40, borderColor: "gray", borderWidth: 1 }} | |
/> | |
); | |
}; | |
const MyForm = () => ( | |
<Formik | |
initialValues={{ email: "" }} | |
onSubmit={(values, { setSubmitting }) => { | |
console.log(values); | |
alert(values); | |
setSubmitting(false); | |
}} | |
render={({ isSubmitting, handleSubmit }) => { | |
return ( | |
<View> | |
<Field name="email" component={MyTextInput} /> | |
<Button | |
onPress={handleSubmit} | |
title="Submit" | |
disabled={isSubmitting} | |
/> | |
</View> | |
); | |
}} | |
/> | |
); | |
export default class App extends React.Component { | |
render() { | |
return ( | |
<View style={styles.container}> | |
<MyForm /> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
backgroundColor: "#fff", | |
alignItems: "center", | |
justifyContent: "center" | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment