我只是想做這樣的事情(當用戶選擇一個專案,然后導航到另一個組件):
const handleValueChange=(itemValue, itemIndex) =>setTypeValue(itemValue)
const onPress = () => {
try{
const topic = "Plant/type";
...
navigation.navigate('Air')
}catch(err){
console.log(err)
}
}
return (
<Picker
selectedValue={typeValue}
onValueChange={handleValueChange}
style={{ top: '21%', height: 50, width: 150 }}/>
<TouchableOpacity
style={styles.button}
onPress={()=> onPress()}
/>
)
通常,當我們想在兩個組件之間傳遞值時,我們使用 props :
<AirScreen typeofPlant={typeValue} />
但在這種情況下,我不知道如何在不呼叫 AirScreen 的情況下做到這一點
uj5u.com熱心網友回復:
只需執行以下操作:
navigation.navigate('RouteName', { /* params go here */ })
您可能需要閱讀以下檔案: https ://reactnavigation.org/docs/params/
uj5u.com熱心網友回復:
你可以這樣做:
const onPress = () => {
try{
const topic = "Plant/type";
...
navigation.navigate('Air', {newTopic: topic}) //you can pass another value by separating with comma
}catch(err){
console.log(err)
}
}
然后您可以在下一個螢屏中獲取相同的值,例如:
function NextScreen({ route, navigation }) {
const topic = route.params.newTopic
}
希望這對你有用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/410838.html
標籤:
