• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

222
Views
obtener y pasar parámetros en la navegación de reacción

Al presionar un botón, necesito pasar parámetros a otra pantalla donde se obtiene el valor de ese botón, código a continuación;

pantalla: 1

 <TouchableOpacity onPress={() => navigation.navigate("Quiz", { fetch: "history" })} style={styles.button} > <Text style={styles.buttonText}>History</Text> </TouchableOpacity>

pantalla: 2

 const Quiz = ({ navigation, route }) => { const { fetch } = route.params; const getQuiz = async () => { setIsLoading(true); const url = `https://herokuapp.com/q/${fetch}`; const res = await fetch(url); const data = await res.json(); setQuestions(data.results); setOptions(generateOptionsAndShuffle(data.results[0])); setIsLoading(false); };

Pero durante la búsqueda me sale el siguiente error

 [Unhandled promise rejection: TypeError: fetch is not a function. (In 'fetch(url)', 'fetch' is "history")]

He intentado usar el tiempo de espera pero no funciona, ¿hay alguna opción mejor?

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema es que fetch es una función nativa en javascript (ver aquí ).

Debe cambiar el nombre del parámetro a otro nombre como quizz .

pantalla: 1

 <TouchableOpacity onPress={() => navigation.navigate("Quiz", { quizz: "history" })} style={styles.button} > <Text style={styles.buttonText}>History</Text> </TouchableOpacity>

pantalla: 2

 const Quiz = ({ navigation, route }) => { const { quizz } = route.params; const getQuiz = async () => { setIsLoading(true); const url = `https://herokuapp.com/q/${quizz}`; const res = await fetch(url); const data = await res.json(); setQuestions(data.results); setOptions(generateOptionsAndShuffle(data.results[0])); setIsLoading(false); };
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error