Home > database >  how to naviagate in react native between componets
how to naviagate in react native between componets

Time:11-25

i was previosly woeking on react js & i am new to react native i am trying to naviage betwwen componets in my app i am using reactnavigation i dont know whethere this is the easyest way

i have app.js and Dashbord.js

app.js


function HomeScreen(navigation) {
  return (
    <View style={styles.prheight}>
      <View style={styles.prheight}>
        <Text style={styles.r}>Sukhprasavam</Text>
      </View>
      <View style={styles.buttonw}>
        <Button
          color="#7743DB"
          title="Lets Go"
          onPress={() => navigation.navigate('Dashbord')}
        />
      </View>
    </View>
  );
}

const Stack = createNativeStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen
          options={{headerShown: false}}
          name="Home"
          component={HomeScreen}
        />
        <Stack.Screen name="Dashbord" component={Dashbord} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

Dashbord

import React from 'react';
import {StyleSheet, Text, View} from 'react-native';

export default function Dashbord() {
  return (
    <View style={styles.prheight}>
      <View style={styles.prheight}>
        <Text style={styles.r}>dada</Text>
      </View>
      <View style={styles.buttonw}>
        <Button
          color="#7743DB"
          title="Lets Go"
       
        />
      </View>
    </View>
  );
}

the error i am getting is undefined is not a funtion on this line onPress={() => navigation.navigate('Dashbord')}

CodePudding user response:

A little change in HomeScreen function: HomeScreen(navigation) to HomeScreen({ navigation })

If you want use HomeScreen(navigation), just change onPress function: onPress={() => navigation.navigate('Dashbord')} to onPress={() => navigation.navigation.navigate('Dashbord')}

CodePudding user response:

visit this link for guidance enter link description here

  • Related