Ниже мой код, у меня есть ошибка: undefined не является объектом (оценка 'navigation.navigate') - PullRequest
0 голосов
/ 03 мая 2020

Я новичок, чтобы реагировать на нативный, я пытаюсь поработать над TouchableOpacity onPress, чтобы перейти к экрану SignUp: Однако TypeError: undefined не является объектом (оценивается как «navigation.navigate»)

Ниже мой код:

import React from 'react';
import { Text, StyleSheet, TextInput, TouchableOpacity, KeyboardAvoidingView } from 'react-native';

function Regform ({navigation}) {
        return (
            <KeyboardAvoidingView behavior="padding" style={styles.regform}>
                <Text style={styles.welcome}> Welcome! </Text>
                <Text style={styles.header}>Let's begin. Please fill out the information below.</Text>

                <TextInput
                    placeholder="Your name"
                    style={styles.textinput}
                    underlineColorAndroid={'transparent'}
                    onSubmitEditing={() => React.yourdob.focus()} />

                <TextInput
                    placeholder="Your date of birth"
                    style={styles.textinput}
                    underlineColorAndroid={'transparent'}
                    ref={(input) => React.yourdob = input}
                    onSubmitEditing={() => React.youremail.focus()} />

                <TextInput
                    placeholder="Your email"
                    style={styles.textinput}
                    underlineColorAndroid={'transparent'}
                    ref={(input) => React.youremail = input}
                    onSubmitEditing={() => React.passwordInput.focus()} />

                <TextInput
                    placeholder="Your password"
                    style={styles.textinput}
                    secureTextEntry={true}
                    underlineColorAndroid={'transparent'}
                    ref={(input) => React.passwordInput = input} />

                <TouchableOpacity style={styles.button} 
                **onPress={() => navigation.navigate('Login')} >**
                    <Text style={styles.btntext}>Sign up </Text>
                </TouchableOpacity>

            </KeyboardAvoidingView>
        );
    }
export default Regform;

1 Ответ

0 голосов
/ 03 мая 2020

react-navigation передает navigation объект своему прямому потомку. Так что я думаю, что Regform не является прямым потомком навигации. Вы можете передать навигационный объект от предков, которые являются дочерними элементами навигации, или использовать useNavigation.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...