I have two simple questions. The first question deals with being able to navigate to a functional screen. I have a stack of screens in App.js. In my Home screen, you can see I ask the user for location permissions and log the latitude and longitude. I would like to be able to navigate from my Home screen to Screen1. You can see below how I am attempting to do so, I can do it with components but I am confused how to do it with functions.
My second question is dealing with the latitude and longitude states. I would like to access those values on Screen1. How can I pass those states to screen1 to be able to display them?
Here is the code below as well as a working snack demo here.
I appreciate any insight more than you know. Thank you.
App.js
export default function MyTabs() {
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName="Home">
<Stack.Screen name="Home" component= {Home} options={{headerShown: false}}/>
<Stack.Screen name="Screen1" component= {Screen1} options={{headerShown: false}}/>
</Stack.Navigator>
</NavigationContainer>
);
}
Home.js
return (
<View style={styles.container}>
<Text style={styles.paragraph}>{latitude}</Text>
<Text style={styles.paragraph}>{longitude}</Text>
<TouchableOpacity onPress={() => navigation.navigate('Screen1')}>
<Text style={styles.paragraph}>Click me to go to screen1</Text>
</TouchableOpacity>
</View>
);
}
Screen1.js
export default function Screen1() {
const [latitude, setLatitude] = useState(null);
const [longitude, setLongitude] = useState(null);
return (
<View style={styles.container}>
<Text style={styles.paragraph}>{latitude}</Text>
<Text style={styles.paragraph}>{longitude}</Text>
</View>
);
}
