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

694
Views
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 answers
Answer question

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 Report

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 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!