-
-
Save andriangungon/f5e8538bb0b3932407885b771cd6f80d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function HomeScreen({ navigation }) { | |
return ( | |
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | |
<Text>Home Screen</Text> | |
<Button | |
title="Go to Details" | |
onPress={() => { | |
/* 1. Navigate to the Details route with params */ | |
navigation.navigate('Details', { | |
itemId: 86, | |
otherParam: 'anything you want here', | |
}); | |
}} | |
/> | |
</View> | |
); | |
} | |
function DetailsScreen({ route, navigation }) { | |
/* 2. Get the param */ | |
const { itemId } = route.params; | |
const { otherParam } = route.params; | |
return ( | |
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | |
<Text>Details Screen</Text> | |
<Text>itemId: {JSON.stringify(itemId)}</Text> | |
<Text>otherParam: {JSON.stringify(otherParam)}</Text> | |
<Button | |
title="Go to Details... again" | |
onPress={() => | |
navigation.push('Details', { | |
itemId: Math.floor(Math.random() * 100), | |
}) | |
} | |
/> | |
<Button title="Go to Home" onPress={() => navigation.navigate('Home')} /> | |
<Button title="Go back" onPress={() => navigation.goBack()} /> | |
</View> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment