Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda