skip to Main Content

I want to do a simple task which is go from one screen to another but no matter what i do it won’t work. I’ve installed both the react-navigation/stack and react-navigation/native-stack and neither work with what i have, is it because Tabs?

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import Tabs from './navigation/tabs';
import "react-native-url-polyfill/auto"
import LogInSignUp from './SettingsScreen/LogInSignUp';


const Stack = createStackNavigator();

const App = () => {
    return (
        <NavigationContainer>
          <Stack.Navigator screenOptions={{ headerShown: false }}>
            <Stack.Screen name="Home" options={{title: "Welcome"}} component={Tabs} />
            <Stack.Screen name="Settings" component={Tabs} />
            <Stack.Screen name = "LogInSignUp" component={LogInSignUp}/>
          </Stack.Navigator>
    </NavigationContainer>
  );
};

export default App;

import { Text, StyleSheet, View, Button, } from "react-native";
import { StatusBar } from "expo-status-bar";


const Settings = (navigation) => {
    return (
      <View style = {styles.container}>
        <Button title = "LogIn/SignUp" onPress={() => navigation.navigate("LogInSignUp")}></Button>
      </View>
      
    );
  }

  const styles = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
    },
    
  })

export default Settings

import React from 'react'
import { StackActions } from '@react-navigation/native';

const LogInSignUp = (navigation) => {
  return (
    <div>LogInSignUp</div>
  )
}

export default LogInSignUp

I tried to find tutorials explaining the problem and all of their code looks like mine with just switched out names to my .js files and nothing works.

2

Answers


  1. Did you tried this hook

    const navigation = useNavigation();

    import {useNavigation} from '@react-navigation/native';
    
    const Settings = () => {
    const navigation = useNavigation();
        return (
          <View style = {styles.container}>
            <Button title = "LogIn/SignUp" onPress={() => navigation.navigate("LogInSignUp")}></Button>
          </View>
        );
      }
    
    Login or Signup to reply.
  2. You’re not destructuring your props. You’re receiving the props as navigation. In you’re case you should use navigation.navigation.navigate.

    This should resolve the issue

    const Settings = ({ navigation }) => {
      // ...
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search