Problems with navigation, not functioning properly due to issues with Pulled functions

I am still getting the hang of things and struggling with the terminology, so please bear with me as I try to explain my issue.

Currently, I am working on a project in react native where I have two files - Header.js and footer.js. I have successfully imported them into my Home Screen but now I am facing an issue with the buttons inside footer.js not functioning properly. The error message states 'undefined is not an object (evaluating 'navigation.navigate')'. How can I restore the functionality?

Any assistance would be greatly appreciated. Below is a snippet of my project for reference;

import React from 'react';
import TabNavigator from "./assets/component/TabNavigator";
import {StackNavigation} from "./assets/component/StackNavigation";


export default function App() {
    return (
       <StackNavigation/>
    );
}

StackNavigation.js;

import React from 'react';
import { HomeScreen} from "../Screens/HomeScreen";
import LayoutProps from "../Screens/Layout Props";
import SampleViewProps from "../Screens/SampleViewProps";
import {NavigationContainer} from "@react-navigation/native";
import {createNativeStackNavigator} from "@react-navigation/native-stack";

const Stack = createNativeStackNavigator();

export function StackNavigation() {
    return (
        <NavigationContainer>
            <Stack.Navigator initialRouteName="Home">
                <Stack.Screen name="Home" component={HomeScreen}/>
                <Stack.Screen name="Layout Props" component={LayoutProps} />
                <Stack.Screen name="View Props" component={SampleViewProps} />
            </Stack.Navigator>
        </NavigationContainer>
    );
}

HomeScreen.js;

import React from 'react';
import {Button, View, SafeAreaView, StyleSheet} from 'react-native';
import HeaderSB from "../component/SBHeader";
import FooterSB from "../component/SBFooter";

export function HomeScreen({navigation}) {

    const receiveValue = (value) => {
        console.log("value received from B", value)
    }

    return (
        <>
            <SafeAreaView style={styles.container}>
                <View style={styles.headerContainer}>
                    <HeaderSB receiveValue={receiveValue}>
                    </HeaderSB>
                </View>
                <View style={styles.mainContent}>
                    <View style={styles.buttonBox}>
                        <Button onPress={() => navigation.navigate('Layout Props')} title="Layout Props"/>
                        <Button onPress={() => navigation.navigate('View Props')} title="View Style Props"/>
                    </View>
                </View>
                <View styles={styles.footerContainer}>
                    <FooterSB receiveValue={receiveValue}>
                    </FooterSB>
                </View>

            </SafeAreaView>
        </>
    );
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "space-between",
    },
    headerContainer: {

    },
    mainContent: {

    },
    buttonBox: {}
    ,
    footerContainer: {

    },
});

Footer.js;

import * as React from "react";
import {StyleSheet, TouchableOpacity, View} from "react-native";
import {AntDesign, Feather} from "@expo/vector-icons";
import {StackNavigation} from "./StackNavigation";

const FooterSB = ({navigation}) => {
    return (
        <>
            {/* Bottom App Navigation */}
            <View style={footerStyle.navCon}>
                <View style={footerStyle.navBar}>

                    {/* Home Button */}
                    <TouchableOpacity style={footerStyle.home} onPress={() =>
                        navigation.navigate('Home')}
                    >
                        {/* Icon */}
                        <AntDesign name="home" size={50} color="white"/>
                    </TouchableOpacity>

                    {/* Navigation Divider */}
                    <View style={footerStyle.navDivider}/>

                    {/* Setting Button */}
                    <TouchableOpacity style={footerStyle.settings} onPress={() =>
                        navigation.navigate('Layout Props')}
                    >
                        {/* Icon */}
                        <Feather name="settings" size={50} color="white"/>
                    </TouchableOpacity>
                </View>
            </View>
        </>

    );
}

const footerStyle = StyleSheet.create({
    navCon: {
        flex: 1,
        marginTop: 20,
        alignItems: "center",
        justifyContent: "flex-end"
    },
    navBar: {
        flexDirection: "row",
        justifyContent: "space-evenly",
        alignItems: "center",
        backgroundColor: "#808080",
        width: 500,
        height: 50,
    },
    home: {
    
    },
    navDivider: {
        backgroundColor: "#FFF",
        width: 4,
        height: 50,
    },
    settings: {
       
    },
});

export default FooterSB;

Answer №1

If you'd like to have default navigation as a prop, you should include it within <Stack.Screen>. However, since FooterSB is a custom component, it won't automatically receive the navigation prop.

In order to pass the navigation prop, you need to make the following change:

<FooterSB receiveValue={receiveValue}>
</FooterSB>

Update it to:

<FooterSB receiveValue={receiveValue} navigation={navigation}>
</FooterSB>

You can also pass the navigation prop to the header in a similar manner.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Filtering React Tables with Next.js

I am encountering an issue with the filtering functionality of a component that utilizes React Table. Despite inputting a search term into the designated field, the filtering process seems to initiate momentarily but then nothing happens. I have simply cop ...

Transformation of looks post a refresh

Initially, the CSS and appearance of the page look fine when I first open it (after clearing the cache). However, upon refreshing the page, a part of it changes (specifically, the padding direction of a div). This change occurs consistently with each refre ...

Connect ngOptions to an array beyond the current scope

Can the ngOptions be bound to a value that is not within the $scope? I have enums that will be generated as JavaScript code. These enums are not currently part of "the angular domain", but I want to bind an ngOptions to one of the arrays without manually ...

Obtain the data from onTouchTap action

Currently, I have a class that is returning an event to the parent. My goal is to extract the number of the touched button (the label on RaisedButton). Although I am successfully returning the event, I am unable to locate the desired information when I l ...

Using JavaScript, you can manipulate the position of a line on a canvas to

I want to create a feature where users can manipulate lines on a canvas by skewing them. This means they would be able to drag one end point of the line to a desired point on the same x-axis using JavaScript and HTML5 canvas. Can someone please provide g ...

Encountering an "undefined is not a function" error across all libraries

While working on ASP.Net MVC4, I have encountered an issue where I consistently receive the error message "undefined is not a function" when using jQuery functions with different libraries. Despite ensuring that every ID is correct and everything has bee ...

What's the trick to ensuring that state is set with useEffect() every time the page is refreshed?

Hey there! I've got some code that's pretty straightforward and not too complicated, so please take a moment to read through it. (I'm using React with Next.js) First off, in the root file app.js, there's a useEffect function that fetch ...

Express 4.13.4 appears to be disregarding the cookie's expiration date when the moment.toDate() function is used

I've been encountering an issue where I am attempting to set a cookie with a specific expiry date of 3 months, but the expiration is not setting correctly. Using momentJS, I created a date object for the desired time. The console confirms that the co ...

A guide on passing variables to the MUI styled function within ReactJS

Is it possible to pass a variable directly to the styled function in order to conditionally change style properties while using MUI styled function? I want to achieve something like this: borderColor: darkMode ? 'white' : 'black' const ...

Error during minification process for file opentok.js at line 1310: react-scripts build

I encountered an error while trying to minify the code in my React project using npm run build. The snippet below seems to be the cause of the issue. Any suggestions on how I can resolve this problem? const createLogger = memoize(namespace => { /** ...

Node.JS has deceived us with its false promises of `import` support

Could it be that I am making a mistake? I have been eagerly awaiting the experimental ES6 module loader in Node.JS since version 10. This feature is crucial for me to seamlessly use the same code in both the browser and node environments. This is how I w ...

Is it possible to expand the Angular Material Data Table Header Row to align with the width of the row content?

Issue with Angular Material Data Table Layout Link to relevant feature request on GitHub On this StackBlitz demo, the issue of rows bleeding through the header when scrolling to the right and the row lines not expanding past viewport width is evident. Ho ...

Issue with setting HTML content using jQuery's .html() method

I have a simple functionality. When a user clicks on the edit link, it transforms the previous element into an input element for editing, and changes the edit link into a cancel link. If the user decides not to edit, they can click on cancel and everything ...

Updating the font style in MUI with React 18

I attempted to create a new theme in order to replace the default font family of MUI but unfortunately, it was not successful. This is what my theme component looks like: import { createTheme } from "@mui/material/styles"; const theme = createT ...

Struggling with a minor glitch in a straightforward coin toss program written in JavaScript

I'm a newcomer to JavaScript programming and I am struggling with understanding how the execution flow is managed. I attempted to integrate an animation from "Animation.css" into a coin toss program, but encountered an issue. When trying to use JavaSc ...

Improving efficiency of basic image carousel in Angular 8

In my Angular 8 app, I am developing a basic carousel without relying on external libraries like jQuery or NgB. Instead, I opted to use pure JS for the task. However, the code seems quite cumbersome and I believe there must be a more efficient way to achie ...

Tips for safely executing an SQL query with electron.js

I have a new project where I need to interact with an SQL database on the local network, but it's not located on the same system I'm working on (not SQLExpress). So far, I've figured out how to collect user input on a webpage and send that ...

Dragging objects on a map is done using jQuery and it causes them to bounce

Currently, I am working on implementing the JQuery Draggable feature. My idea is to create a map where I can attach image Divs to it dynamically using Jquery. So far, I have been successful in adding the Divs and making them draggable around the map effici ...

The text sliding feature gradually moves further away from the left side with each iteration

I am in the process of transferring an existing slider from one website to another. Instead of creating a text slider from scratch, I decided to modify the code I found for the new site. However, the slider is not functioning correctly on the new site. Th ...

"Enhance your website with a sleek Bootstrap navigation system featuring dividers and

Need help with creating a Bootstrap nav menu similar to this design made in Photoshop? Wondering about the best way to position the logo and create dividers between menu items like shown in this image. Here's the HTML code currently being used: & ...