-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
65 lines (58 loc) · 1.47 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Formik, FormikProps } from 'formik';
import * as Yup from 'yup';
import {myFieldsType,onSubmit,emailAsyncValidation} from './src/util';
import MyForm from "./src/myForm";
import Constants from 'expo-constants';
const initialValues: myFieldsType = { name: '', email: '' }
const validationSchema = Yup.object({
name: Yup.string()
.required('Required'),
email: Yup.string()
.email('Invalid Email')
.required('Required')
.test('checkDuplEmail', 'This email already exists', emailAsyncValidation)
})
export default () => {
return <View style={styles.container}>
<Text style={styles.title}>Formik/Yup to Firebase</Text>
<Formik
initialValues={initialValues}
validationSchema={validationSchema}
onSubmit={onSubmit}
>
{ (props : FormikProps<myFieldsType> ) => (
<MyForm {...props} />
)}
</Formik>
</View>
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: Constants.statusBarHeight + 50,
backgroundColor: '#ecf0f1',
padding: 8,
},
title: {
margin: 24,
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center',
},
error: {
margin: 8,
fontSize: 14,
color: 'red',
fontWeight: 'bold',
},
input: {
height: 50,
paddingHorizontal: 8,
width: '100%',
borderColor: '#ddd',
borderWidth: 1,
backgroundColor: '#fff',
},
});