【发布时间】:2022-01-14 10:27:26
【问题描述】:
我只是想做类似的事情(当用户选择一个项目,然后导航到另一个组件):
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 的情况下做到这一点
【问题讨论】:
-
导航时可以传递路由状态的数据。 reactnavigation.org/docs/params
标签: javascript reactjs react-native ecmascript-6 react-props