0

Im new to React Native so I apologize for ignorance.

See code below.....when it gets to const { routeName } = navigation.state; ....it gives error [TypeError: Cannot read property 'routeName' of undefined].

I can see the navigation object contains a "state" object....and that this object contains a routeName key (named "Search")....so why doesnt it recognize.

Thanks for help

import React, { Component } from 'react';
import { TabNavigator, TabBarBottom } from 'react-navigation';
import { Platform } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';

import Search from '../screens/Search';
import Profile from '../screens/Profile';


export const Tabs = TabNavigator(
{
  Search: {
    screen: Search,
    navigationOptions:{
        tabBarLabel:'Search'
    }
  },
  Profile: {
    screen: Profile,
    navigationOptions:{
        tabBarLabel:'Me'
    },
  }
}, //end of 1st object/arg passed to TabNavigator
{
  navigationOptions: ( navigation ) => ({
    tabBarIcon: ({ focused, tintColor }) => {
      const { routeName } = navigation.state;
      let iconName;
      if(routeName === 'Search'){
        iconName = "ios-information-circle" + (focused ? "" : "-outline");
      } else if (routeName === 'Profile') {
        iconName = "ios-options" + (focused ? "" : "-outline");
      }

  return <Ionicons name={iconName} size = {25} color = {tintColor} />;
    }, //end tabBarIcon
  }), //end navigationOptions

  tabBarOptions: {
    activeTintColor: 'tomato',
    inactiveTintColor: 'gray'
  },

  tabBarComponent: TabBarBottom,
  tabBarPosition: 'bottom',
  animationEnabled: false,
  swipeEnabled: false

} //end 2nd arg/object passed to TabNavigator
); //end TabNavigator

1 Answer 1

1

Figured it out.....was missing curly brackets around the navigation argument passed to navigationOptions. Newby mistake :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.