Solo estoy tratando de hacer algo así (cuando el usuario selecciona un elemento, luego navega a otro componente):
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()} /> )Por lo general, cuando queremos pasar valor entre dos componentes, usamos accesorios:
<AirScreen typeofPlant={typeValue} />Pero en este caso no tengo idea de cómo puedo hacerlo sin invocar AirScreen
Puedes hacer eso como:
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) } }Luego puede obtener el mismo valor en la siguiente pantalla como:
function NextScreen({ route, navigation }) { const topic = route.params.newTopic }Espero que esto funcione para usted.
Solo haz algo como esto:
navigation.navigate('RouteName', { /* params go here */ })Es posible que desee leer la siguiente documentación: https://reactnavigation.org/docs/params/