Melewati parameter ke rute
class HomeScreen extends React.Component { render() { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>Home Screen</Text> <Button title="Go to Details" onPress={() => { this.props.navigation.navigate('Details', { itemId: 86, otherParam: 'anything you want here', }); }} /> </View> ); }}
class DetailsScreen extends React.Component { render() { const { navigation } = this.props; return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>Details Screen</Text> <Text> itemId: {JSON.stringify(navigation.getParam('itemId', 'NO-ID'))} </Text> <Text> otherParam: {JSON.stringify(navigation.getParam('otherParam', 'default value'))} </Text> <Button title="Go to Details... again" onPress={() => navigation.push('Details', { itemId: Math.floor(Math.random() * 100), }) } /> </View> ); }}
Light Leopard