3

I Use Custom Drawer on React Native. and I Have 3 Bottom Tab Navigator. Chat, Home and Profile Tab. And then on Home I create some of box, if box clicked, it would be navigate to another view. home menu

this is MenuHome Component that i called when the Home Navigation Pressed.

const MenuHome = ({ navigation }) => {
  return (
    <View style={styles.container}>
      <TouchableOpacity
          style={styles.box}
          onPress={() => navigation.navigate('CashBank')}
       >
       <View style={styles.inner}>
         <Text style={styles.titleText}>CASH BANK</Text>
       </View>
      </TouchableOpacity>
    </View>
  )
}

and I import MenuHome on Home Component.

const Home = ({ navigation }) => {
  return (
    <View>
      <MenuHome />
    </View>
  )
}

and i've been create CashBank Component, but i get error Undefined is not object (evaluating 'navigation.navigate')

1 Answer 1

1

Your MenuHome component takes the navigation as prop so you have to pass the navigation object to it

const Home = ({ navigation }) => {
      return (
        <View>
          <MenuHome navigation={navigation} />
        </View>
      )
    }

Another solution would be to use the hook provided by the library in your MenuHome component

import {useNavigation} from '@react-navigation/native';
const MenuHome = () => {
  const navigation = useNavigation();
  return (
    <View style={styles.container}>
      <TouchableOpacity
          style={styles.box}
          onPress={() => navigation.navigate('CashBank')}
       >
       <View style={styles.inner}>
         <Text style={styles.titleText}>CASH BANK</Text>
       </View>
      </TouchableOpacity>
    </View>
  )
}
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.