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

169
Views
React Native: How to navigate from inside the NavigationContainer?

I have a component in my Navigation.tsx which controls the routes within my application. The component sits inside one of my Stack.Screen's under headerRight . Im trying to navigate to a different screen when the component is clicked. However, im unable to get that working for this particular component. Routing outside my Navigation file works perfectly fine, but not within.

Im unable to figure out what i am missing or what needs to be changed.

Code below: headerRight under ItemDetails

export default function Navigation( { navigation }) {
const Stack = createStackNavigator();

const MyTheme = {
    ...DefaultTheme,
    colors: {
      ...DefaultTheme.colors,
      background: '#FFF',
    }
}

return (
    <NavigationContainer theme={MyTheme}>
        <Stack.Navigator initialRouteName="Home">

            <Stack.Screen name="Home" component={Home} options={({route}) => ({
                headerShown: false,
            })}/>
            <Stack.Screen name='CartDetails' component={CartDetails}/>
            <Stack.Screen name="ItemDetails" component={ItemDetails} options={({route}) => ({
                title: false,
                headerTitle: false,
                headerBackTitleVisible: false,
                headerTransparent: true,
                headerShadowVisible: false,
                headerRight: () => (
                    <TouchableOpacity onPress={() => { navigation.navigate('CartDetails')}}>
                        <CartIcon />
                    </TouchableOpacity>
                ),
                headerBackImage: () => (
                    
                        <View style={{backgroundColor: '#ffffff', borderRadius: '50%', marginLeft: 15, marginBottom: 5}}>
                            <Entypo name="chevron-small-left" size={30} color="#37BD6B"/>
                        </View>
                )
            })} />

        </Stack.Navigator>
    </NavigationContainer>
)

}

Thanks in advance

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

0

I managed to solve the problem.

Rather than passing headerRight an argument, passing it to 'option' gives you the correct result.

 options={({route, navigation}) => ({ 
                title: false,
                headerTitle: false,
                headerBackTitleVisible: false,
                headerTransparent: true,
                headerShadowVisible: false,
                headerRight: () => (
                    <TouchableOpacity onPress={() => navigation.navigate('CartDetails')}>
                        <CartIcon />
                    </TouchableOpacity>
                ),
                headerBackImage: () => (
                    
                        <View style={{backgroundColor: '#ffffff', borderRadius: '50%', marginLeft: 15, marginBottom: 5}}>
                            <Entypo name="chevron-small-left" size={30} color="#37BD6B"/>
                        </View>
                )
            })}  />
about 4 years ago · Juan Pablo Isaza Report

0

React Navigation provides the navigation object as an argument to the header callbacks. You can take it from there.

  headerRight: ({ navigation }) => (
    <TouchableOpacity onPress={() => { navigation.navigate('CartDetails')}}>
      <CartIcon />
    </TouchableOpacity>
  ),
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!