Skip to content

Instantly share code, notes, and snippets.

@macouella
Created October 9, 2018 07:06
Show Gist options
  • Save macouella/c24297564e2b750e2cc1feacb0bffbb4 to your computer and use it in GitHub Desktop.
Save macouella/c24297564e2b750e2cc1feacb0bffbb4 to your computer and use it in GitHub Desktop.
For Simon
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