Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
fetching and passing params in react navigation

On Press of a button I need to pass params to another screen where value of that button is fetched, code below;

screen:1

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

screen: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);
  };

But during the fetching I get the following error

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

I have tried using timeout but that is not working, is there a better option.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The issue is that fetch is a native function in javascript (see here).

You should rename the param to another name like quizz.

screen:1

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

screen: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);
  };
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda