es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Botón React Native navegar hacia otra página.

Soy nuevo en React Native. Necesito que al hacer clic en un botón, aparezca una nueva página. Ya he intentado algunas cosas, pero tal vez el problema esté en otro lugar.
Pegaré mi código debajo. ¡Por favor, ayúdame!

Explicación adicional: Quiero hacer clic en el botón y luego debería ir a otra página.

““importar { StatusBar } de “expo-status-bar”;
importar React, { useState } de “react”;
import {
StyleSheet,
Text,
View,
Image,
TextInput,
TouchableOpacity,
Linking,
Button
} de “react-native”;
importar { useNavigation } desde ‘@react-navigation/native’;
import “react-native-gesture-handler”;
importar { NavigationContainer } desde ‘@react-navigation/native’;
importar { createStackNavigator, createAppContainer } de ‘react-navigation’;

exportar función por defecto App() {
const [email, setEmail] = useState(“”);
const [password, setPassword] = useState(“”);

return (



setEmail(email)}
/>

Tags:  , , ,

Answer

  1. Avatar for davy.ai

    Parece que falta la propiedad navigation en el componente Button. Necesita envolver el componente App con un NavigationContainer y luego pasar la propiedad navigation al componente Button.

    import { NavigationContainer } from '@react-navigation/native';
    
    export default function App() {
      const [email, setEmail] = useState("");
      const [password, setPassword] = useState("");
      const navigation = useNavigation();
    
      return (
        <navigationcontainer>
          <view style="{styles.container}">
            <image style="{styles.image}" source="{require("./assets/logo.png")}"></image>
    
            <statusbar style="auto"></statusbar>
            <view style="{styles.inputView}">
              <textinput style="{styles.TextInput}" placeholder="Benutzername" onchangetext="{(email)" ==""> setEmail(email)}
              />
            </textinput></view>
    
            <button style="{styles.loginBtn}" title="Go to Profile" onpress="{()" ==""> navigation.navigate('Profile')}  
            />  
          </button></view>
        </navigationcontainer>
      );
    }
    

Comments are closed.