Why can't I pass an object to `navigation.navigate()`?

355 Views Asked by At

I'm using the UI Kitten library. I can store routes in an array and pass an array index to navigate()

Here's what I'm doing. I store my routes in an array like this:

const routeNames = [
  'Customers',
  'Employees',
]

And then I reference them on a navigation tab:

<BottomNavigation
    selectedIndex={state.index}
    onSelect={onSelect}
>
  <BottomNavigationTabItem
      title={routeNames[0]}
  />
...

And handle on select:

const onSelect = index => {
    navigation.navigate(routeNames[index]);
  };

But I would rather reference their name for better readability like this:

<BottomNavigationTabItem
          title={routeNames.Customer}
      />

And therefore store the route names in an object:

const routeNames = {
      CustomerList: 'Customers',
      EmployeeList: 'Employees',
    }

But doing it this way with the object gives me an error:

You need to specify name or key when calling navigate with an object as the argument

I feel like it shouldn't matter as long as I pass a string for the route name.

UPDATE: It looks like the docs say a number type is required for onSelect ... but is the array index not referencing a string? What do I not understand about how array references work?

0

There are 0 best solutions below