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

249
Views
react native : why my screen's param(props) can't be passed while using stack navigator?

App.js

const Stack = createNativeStackNavigator();

export default function App() {
  return (
    <Provider store={store}>
      <NavigationContainer>
        <Stack.Navigator initialRouteName="Main">
          <Stack.Screen options={{headerShown: false}} name="Main" component={MainScreen} />
          <Stack.Screen options={{headerShown: false}} name="Report" component={ReportScreen} />
        </Stack.Navigator>
      </NavigationContainer>
    </Provider>
  );
}

./screens/ReportScreen.js

import React from 'react';
import {
  StyleSheet,
  SafeAreaView,
  View,
  Text,
} from 'react-native';
import ReportReason from '../components/ReportReason';

const ReportScreen = ({route}) => {
    
    const textVal = '';
    if (route.param.title.length > 12){
        textVal = route.params.title.substring(0,10) + '...';
    }
    else {
        textVal = route.params.title;
    }
    
    return(
        <SafeAreaView style = {reportStyles.container}>
            <View style = {reportStyles.card}>
                <Text>Report</Text>
                <Text>{textval}</Text>
                <ReportReason/>
            </View>
        </SafeAreaView>
    );
};

part of ./components/ReportMension.js

const ReportMension = ({mension}) => {

return(

TouchableOpacity style={postModalStyles.listButton} onPress={()=>{
console.log(mension)
navigation.navigate('Report', { title: mension.title });
}}>
            <Text style={postModalStyles.text}>report</Text>
        </TouchableOpacity>

);
}

this is component of screen named Main.

console.log is operated normally. why my component and navigator are cannot passed params(props)? how to pass props when using stack navigaor??

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First, in ReportMention, you can't reassign a const variable. Instead, try

    let textVal = '';
    if (route.params.title.length > 12) {
        textVal = route.params.title.substring(0,10) + '...';
    }
    else {
        textVal = route.params.title;
    }

Or

const textVal = route.params.title.length > 12
  ? route.params.title.substring(0,10) + '...'
  : route.params.title;

Second, there's a typo in the condition: route.param.title.length should be route.params.title.length. This would throw an error, since you can't access the property length on an object that is undefined.

These two syntax errors should prevent fast refresh from working, since the result wouldn't compile. If you fix these, and console.log the route object in ReportMention, you should get the params you're looking for.

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!