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
<Input | |
type="file" | |
name="file" | |
onChange={handleChange("file")} | |
/> |
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
<Input | |
type="file" | |
name="file" | |
onChange={(event) =>{ | |
setFieldValue("photo1", event.target.files[0]); | |
}} | |
/> |
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
handleSubmit = (values) => { | |
let data = new FormData(); | |
data.append("photo1", values.photo1); | |
return fetch(baseUrl, { | |
method: "post", | |
headers: new Headers({ | |
Accept: "application/json", | |
Authorization: "Bearer " + token, | |
}), | |
body: data, |
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
<Formik initialValues={{ email: '', password: ''}} onSubmit={this.handleSubmit}> | |
{(formProps) => ( | |
<View> | |
<TextInput | |
value={formProps.values.email} | |
onChangeText={formProps.handleChange('email')} | |
placeholder="Enter Email" | |
/> | |
<TextInput | |
value={formProps.values.password} |
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
<Formik | |
initialValues={{ email: '', password: ''}} | |
validationSchema={yup.object().shape({ | |
email: yup | |
.string() | |
.email('Invalid Email') | |
.required('Email is Required.'), | |
password: yup.string() | |
.min(6) | |
.required('Password is Required'), |
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
{formProps.errors.email && ( | |
<Text | |
style={{ | |
fontSize: 16, | |
color: 'red', | |
paddingHorizontal: 10, | |
}}> | |
{formProps.errors.email} | |
</Text> | |
)} |
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
<TextInput | |
... | |
onBlur={() => formProps.setFieldTouched('email')} | |
/> | |
{formProps.touched.email && formProps.errors.email && ( | |
<Text | |
style={{ | |
fontSize: 16, | |
color: 'red', | |
paddingHorizontal: 10, |
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
<Formik initialValues={{ ... }} onSubmit={this.handleSubmit}> | |
{(formProps) => ( | |
<View> | |
... | |
<Button | |
title="Log In" | |
disabled={!formProps.isValid} | |
onPress={formProps.handleSubmit} | |
/> | |
</View> |
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
handleSubmit = (values, {props = this.props}) => { | |
let data = { | |
email: values.email, | |
password: values.password, | |
}; | |
return fetch(baseUrl, { | |
method: "post", | |
headers: new Headers({ | |
Accept: "application/json", | |
'Content-Type': 'application/json', |
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, {Component} from 'react'; | |
import {Formik} from 'formik'; | |
import * as yup from 'yup'; | |
import { | |
View, | |
TextInput, | |
Text, | |
Button | |
} from 'react-native'; |
OlderNewer