Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
¿Cómo pasar la variable al botón Alert.alert de React Native onPress?

Estoy tratando de pasar un objeto/variable al botón de la función Alert.alert() onPress . Desafortunadamente, obtengo "undefiend" como resultado. Aquí está mi ejemplo de código;

 console.log("HERE ITEM SHOWS THE CORRECT VALUES", item); Alert.alert( "Warning", "Test message", [ { text: "Cancel", onPress: () => console.log("Cancel Pressed"), style: "cancel" }, { text: "Start", onPress: () => { console.log("-----> HERE I CANNOT GET THE VALUES FOR ITEM", item); } } ] );

¿Cómo puedo pasar los valores? Muchas gracias por su ayuda :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí hay un ejemplo práctico: https://snack.expo.dev/@gavindmello97/moody-raspberries

 <TouchableOpacity onPress = {() => { var tempVarForTest = "StackOverflow" Alert.alert( "Warning", "Test message", [ { text: "Cancel", onPress: () => console.log("Cancel Pressed"), style: "cancel" }, { text: "Start", onPress: () => { alert("-----> HERE I CANNOT GET THE VALUES FOR ITEM "+ tempVarForTest); } } ] ); }}> <Text style={styles.paragraph}> Click me to open alertBox </Text> </TouchableOpacity>

He usado el mismo código que en tu pregunta. Comprueba si me perdí algo. Como lee la variable, también puede leer un objeto, texto, etc.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!