Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How can I resolve this error on my project"[TypeError: undefined is not an object (evaluating '_context.t0.response.data')]"?

$
0
0

I'm pretty inexperienced and I ended up getting the project in the middle and I don't understand it very well. When I try to login or register I get the following error:

    Warning: An unhandled error was caught from submitForm(), [TypeError: undefined is not an object (evaluating '_context.t0.response.data')]    at node_modules\react-native\Libraries\LogBox\LogBox.js:117:10 in registerWarning    at node_modules\react-native\Libraries\LogBox\LogBox.js:63:8 in warnImpl    at node_modules\react-native\Libraries\LogBox\LogBox.js:36:4 in console.warn    at node_modules\expo\build\environment\react-native-logs.fx.js:18:4 in warn    at node_modules\formik\dist\formik.cjs.development.js:928:17 in useEventCallback$argument_0    at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne    at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0    at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer    at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass    at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard    at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue    at [native code]:null in flushedQueue    at [native code]:null in callFunctionReturnFlushedQueue

Login code:

    import React, { useState, useCallback } from 'react';    import { View, Image, Text, TextInput, KeyboardAvoidingView, Platform, Alert } from 'react-native';    import { RectButton, ScrollView } from 'react-native-gesture-handler';    import styles from './styles';    import Logo from '../../assets/images/aci-logo-square.png'    import { useNavigation } from '@react-navigation/native';    import { MaterialCommunityIcons } from '@expo/vector-icons';     import { Formik } from 'formik';    import * as yup from 'yup';    import { useAuth } from "../../contexts/auth";    interface FormValues {      email: string;      senha: string;    }    // Validação de formulário com Yup e Formik //    const loginValidationSchema = yup.object().shape({      email: yup        .string()        .email("Entre com um e-mail válido")        .required('É necessário preencher esse campo corretamente!'),        senha: yup        .string()        .min(8, ({ min }) => `A senha deve conter no mínimo ${min} caracteres`)        .required('É necessário preencher esse campo corretamente!'),    });    const Login: React.FC = () => {      const { navigate } = useNavigation();      const { signIn } = useAuth();      function handletoChangePassword() {        navigate('Alterar senha');      }      function handleNavigateToRegister() {        navigate('Register');      }      const [isFocused1, setIsFocused1] = useState(false);      const [isFocused2, setIsFocused2] = useState(false);      const [loading, setLoading] = useState(false);      const initialValues: FormValues = { email: "", senha: "" };      const handleInputFocus1 = useCallback(() => {        setIsFocused1(true);      }, []);      const handleInputFocus2 = useCallback(() => {        setIsFocused2(true);      }, []);      const handleInputBlur1 = useCallback(() => {        setIsFocused1(false);      }, []);      const handleInputBlur2 = useCallback(() => {        setIsFocused2(false);      }, []);      async function handleSignIn(formValues: FormValues) {        try {          setLoading(true);          await signIn(formValues.email, formValues.senha);        } catch (error) {          setLoading(false);          Alert.alert("Erro!",            `${error.response.data.error}`,            [              { text: "OK"}            ]          );        }      }      return (<KeyboardAvoidingView           behavior={Platform.OS === "ios" ? "padding" : "height"}           enabled style={styles.Container}           keyboardVerticalOffset={Platform.OS === "ios" ? 0 : 0}><ScrollView             keyboardShouldPersistTaps="handled"             showsVerticalScrollIndicator={false}             showsHorizontalScrollIndicator={false}             bounces={false} ><View style={styles.Logo}><Image style={styles.TamanhoLogo} source={Logo} /></View><Text style={styles.TitlePage}>              Faça seu login</Text><Formik              validationSchema={loginValidationSchema}              initialValues={initialValues}              onSubmit={(values) => handleSignIn(values)}>                {({                  handleChange,                  handleBlur,                  handleSubmit,                  values,                  errors,                  touched,                }) => (<><View style={styles.ContainerInput}><View style={[styles.SectionInput, { borderColor: isFocused1 ? '#FCD809' : '#181818'}]}><MaterialCommunityIcons                   style={styles.IconRegister}                  name="email-outline"                   size={24}                   color={isFocused1 ? '#FCD809' : '#c1bccc'}                /><TextInput                  returnKeyType="done"                  autoCapitalize="none"                  placeholder={'E-mail'}                  showSoftInputOnFocus={true}                  style={styles.input}                  placeholderTextColor="#c1bccc"                  onFocus={handleInputFocus1}                  onBlur={() => {                    handleBlur('email')                    handleInputBlur1()                  }}                  onChangeText={handleChange('email')}                  value={values.email}                /></View></View>                {(errors.email && touched.email) &&<Text style={styles.errorText}>{errors.email}</Text>                }<View style={styles.ContainerInput}><View style={[styles.SectionInput, { borderColor: isFocused2 ? '#FCD809' : '#181818'}]}><MaterialCommunityIcons                   style={styles.IconRegister}                  name="lock-outline"                   size={24}                   color={isFocused2 ? '#FCD809' : '#c1bccc'}                /><TextInput                  returnKeyType="done"                  placeholder={'Senha'}                  showSoftInputOnFocus={true}                  style={styles.input}                  placeholderTextColor="#c1bccc"                  onFocus={handleInputFocus2}                  onChangeText={handleChange('senha')}                  onBlur={() => {                    handleBlur('senha')                    handleInputBlur2()                   }}                  value={values.senha}                  secureTextEntry                /></View></View>                {(errors.senha && touched.senha) &&<Text style={styles.errorText}>{errors.senha}</Text>                }<RectButton              style={styles.SubmitEntrar}              onPress={() => handleSubmit()}><Text style={styles.TextSubmitbutton}>Entrar</Text></RectButton></>       )}</Formik><RectButton onPress={()=>{handleNavigateToRegister()}} style={styles.ContainerRegister}><Text style={styles.Text}>Cadastre-se</Text><MaterialCommunityIcons                style={styles.IconNext}                name="login-variant"                 size={22}                 color="white"               /></RectButton></ScrollView></KeyboardAvoidingView>      );    }    export default Login;

Does anyone know what I can do to resolve this error?.........................................................................................................................................................


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>