Error: Cannot read property 'map' of undefined in React-Native

I am attempting to display a series of icons from an array called icons. However, when I try to use

{icons.map((icon, index) =>(<Icon key = {index} icon={icon}/>)}
, I encounter the error message "typeError: undefined is not an object (evaluating 'icons.map')".

Below is the code snippet I am working on:

const BottomTabs = ({ icons }) => {
    const [activeTab, setActiveTab]  = useState('Home')

    const Icon = ({icon}) => (
        <TouchableOpacity onPress = {() => setActiveTab(icon.name)}>
            <Image source = {icon.inactive} style= {styles.icon}/>
        </TouchableOpacity>
    )

    return (
        <View>
            { icons.map((icon, index) =>(
                <Icon key = {index} icon={icon}/>
            ))}
        </View>
    )
}

Any insights on what may be causing this issue?

EDIT: This is how I am passing the array to the component:

<BottomTabs icons = {bottomTabIcons}/>

Here is an example of the objects in the array:

const bottomTabIcons = [
    {
        name: 'Home',
        active: require('../../assets/home-active.png'),
        inactive: require('../../assets/home.png') 
    }
]

Is there something wrong with how I am passing the array to my BottomTabs component?

Answer №1

The BottomTabs component was not given any icons. Make sure to pass the icons correctly by using <BottomTabs icons={icons}>

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

The type is lacking the following properties in array.push

Encountering an issue with the register page in my IONIC app. Currently, I am utilizing a data.json file to store all user data, and I aim to create a new member with minimal information required (name, email, password) while leaving other fields empty fo ...

Efficient access to variable-enumerated objects in TypeScript

Let's say I have the following basic interfaces in my project: interface X {}; interface Y {}; interface Data { x: X[]; y: Y[]; } And also this function: function fetchData<S extends keyof Data>(type: S): Data[S] { return data[type]; } ...

It seems that an issue has occurred indicating that something is not defined in the current context

Hello everyone, I'm struggling with a problem that I just can't seem to figure out. I've tried multiple solutions but this error keeps popping up and now I'm completely lost. Can someone please help me resolve this issue? The code in q ...

How can props be defined in Vue3 using Typescript?

When using Vue3's defineComponent function, it requires the first generic parameter to be Props. To provide props type using Typescript interface, you can do it like this: export default defineComponent<{ initial?: number }>({ setup(props) { ...

Refresh your content with the pull-to-refresh feature in Ionic 2

latest-news.html update function <ion-refresher (ionRefresh)="doUpdate($event)"> <ion-refresher-content pullingText="pull to update"> </ion-refresher-content> </ion-refresher> retrieve latest news from server <ion-li ...

Invoking a function on an object of a subclass that derives from an abstract class

In the realm of abstract classes, behold this one: export abstract class BaseStepComponent { /** Behold thy base-step ctor */ constructor() { } abstract getValue(): string; } And lo, here is a component that inherits such abstract glory ...

The role of providers in Angular applications

After creating a component and service in my project, I followed the documentation's instruction to include the service in the providers metadata of the component for injection. However, I found that it still works fine even without mentioning it in t ...

To install the React Native command line interface, use the following command:

Hello, I am encountering an issue while trying to install React Native. When running npm install -g react-native-cli, Command Prompt displays the following error: npm ERR! code EINVAL npm ERR! path C:\WINDOWS\system32\'C:\Users&bso ...

Tips for resolving the setAttribute() function error message: "Argument of type 'boolean' is not assignable to parameter of type 'string'"

I am currently working on a function that dynamically updates the HTML aria-expanded attribute based on whether it is true or false. However, when I declare element as HTMLElement, I encounter an error stating Argument of type 'boolean' is not as ...

When a node_module package includes type imports, Next.js can encounter build failures during the linting and type validity checking processes

This NextJS 13 project utilizes a package that has an inner core dependency (react-leaflet->@react-leaflet/core). When running yarn run build, the build fails at "Linting and checking validity of types." It appears to be a TypeScript compatibility iss ...

Why isn't the page showing up on my nextjs site?

I've encountered an issue while developing a web app using nextjs. The sign_up component in the pages directory is not rendering and shows up as a blank page. After investigating with Chrome extension, I found this warning message: Unhandled Runtime ...

Exporting custom type definitions using a node module

In my project, I have a module named module_core with a specific directory structure as shown below: /src /company /webservices /service-one ... /service-two ... /service-new // my service i ...

Create a TypeScript function that takes multiple functions as parameters and returns a union type consisting of the return values of each function

Would greatly appreciate any assistance with adding types to the following JavaScript function in TypeScript. I've been trying to solve this without resorting to using 'any' for an entire day with no luck. Here's the JavaScript functio ...

Does an async function get automatically awaited if called in a constructor?

I am currently working on updating some code due to a library upgrade that requires it to be made async. The code in question has a base class that is inherited by other classes, and I need to call some functions in the constructor that are now asynchronou ...

Using TypeScript: Implementing array mapping with an ES6 Map

If I have an array of key-value objects like this: const data = [ {key: "object1", value: "data1"}, {key: "object2", value: "data2"}, {key: "object3", value: "data3"}, ] const mappedData = data.map(x => [x.key, x.value]); const ES6Map = n ...

Creating a library that relies on Cypress without the need to actually install Cypress

We have adopted the page object pattern in our testing and recently made the decision to move them into a separate npm-published library for reusability. Considering the heavy nature of Cypress and potential version conflicts, we believe it's best no ...

The error message "vimeo/player.js - Unable to access property 'nativeElement' as it is undefined" appeared

I am encountering difficulties integrating vimeo/player.js into my angular-cli application. There isn't a supporting library for Angular 4, so I'm following the steps in the README.md under "Using with a module bundler". I created a vimeo-player ...

How to Create a Dependency on Tabs for Selecting Items in an Angular 7 Materials Dropdown List

I am currently working with angular 7 in combination with angular materials. In my project, I have implemented a tab as well as a selection list. What I aim to achieve is that the items displayed in the selection list are dependent on the chosen tab in th ...

When you hover over the button, it seamlessly transitions to a

Previously, my button component was styled like this and it functioned properly: <Button component={Link} to={link} style={{ background: '#6c74cc', borderRadius: 3, border: 0, color: 'white', height: 48, padding: '0 ...

Guide to importing a function from a Javascript module without declaration

Currently, I am utilizing a third-party Javascript library that includes Typescript type declarations in the form of .d.ts files. Unfortunately, as is often the case, these type declarations are inaccurate. Specifically, they lack a crucial function which ...