I need to use navigation when pressing the bag icon in the header. When I press it, I get the following error:
undefined is not an object (evaluating '_this.props.navigation')
Screen with bag icon in the header
App.js file:
import React, { Component } from 'react';import { Button, Text, TextInput, View, StyleSheet, TouchableOpacity, Image,} from 'react-native';import { Header } from 'react-navigation-stack';import { NavigationContainer } from '@react-navigation/native';import { createStackNavigator } from '@react-navigation/stack';import TelaInicial from './components/telaInicial';import TelaCarrinho from './components/telaCarrinho';const Stack = createStackNavigator();export default function AppContainer() { return (<NavigationContainer><Stack.Navigator initialRouteName="Inicial"><Stack.Screen name="Inicial" component={TelaInicial} options={{ title: '', headerTintColor: 'white', headerStyle: { backgroundColor: '#6b39b6', height: 100 }, height: Header.height, headerLeft: null, headerTitle: (<View><TouchableOpacity onPress={() => { this.props.navigation.navigate('Carrinho'); }}><Image style={{ width: 29, height: 29, marginTop: 0, marginLeft: 170, }} source={require('./assets/shopping bag.png')} /></TouchableOpacity></View> ), }} /><Stack.Screen name="Carrinho" component={TelaCarrinho} options={{ title: '', headerTintColor: 'white', headerStyle: { backgroundColor: '#6b39b6', height: 100 }, height: Header.height, headerBackTitle: 'Voltar', headerTitle: 'Carrinho'.toUpperCase(), headerTitleStyle: { fontSize: 17, fontWeight: 600, }, }} /></Stack.Navigator></NavigationContainer> );}
Seems simple to make it work, but I've tried many alternatives and it didn't work. Do you guys have any idea how I can fix it?
I have a link to Expo: https://snack.expo.io/@rapolasls/eager-crackers
Thank you!