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

704
Visualizações
TypeError: undefined is not an object (evaluating 'route.params.myText')
function Screen2({route, navigation}) {
  
    
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>{route.params.myText}</Text>
      </View>
    );
  }

export default Screen2;

Here myText is a string that is passed from other screen(login Screen).

login Screen---------------------------------------

<View>
                <Button style={styles.loginBTN} title="Login"
                onPress={() => {navigation.navigate('Screen2'), {myText: "hello react-native"}}} />
            </View>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I guess there's a situation (maybe before unmounting) that route or route.params is undefined,

you can solve it this way

function Screen2({route, navigation}) {  
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>

        //I added question mark before the dots (optional chaining)
        <Text>{route?.params?.myText}</Text>
      </View>
    );
  }
export default Screen2;

it's called optional chaining, according to Mozilla

It enables you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.

about 4 years ago · Juan Pablo Isaza Relatório

0

your login button press should pass the params like below

onPress={() = navigation.navigate("Screen2", {
          myText: "hello react-native",
        })
}
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