TypeError: undefined is not an object(evaluating 'navigation.state')-React Native [英] TypeError: undefined is not an object(evaluating 'navigation.state')-React Native

查看:41
本文介绍了TypeError: undefined is not an object(evaluating 'navigation.state')-React Native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到 TypeError: undefined is not an object(evaluating 'navigation.state') in React Native.

I m getting TypeError: undefined is not an object(evaluating 'navigation.state')in React Native.

const DashboardFooter = ({navigation}) => {
      const activePage = navigation.state.index;
      return (
           <TouchableOpacity
            style={styles.tabIconContainer}
            onPress={() => navigation.navigate('Dashboard')}>
            <Image
              source={
                activePage === 0
                  ? require('../assets/images/dashboard/menu.png')
                  : require('../assets/images/dashboard/menu-active.png')
              }
              style={{width: 24, height: 24}}
             />
            <Text style={styles.titleMenu}>Menu</Text>
          </TouchableOpacity>
        );
    };

我收到此错误!

推荐答案

来自 此处:

您似乎没有正确创建组件,因此设置了 navigation 属性.您需要确保使用 withNavigation 高阶组件.

It seems like you're not properly creating the component so that the navigation property is set. You'll need to make sure to wrap the component using the withNavigation higher order component.

export default withNavigation(MyComponent);

这篇关于TypeError: undefined is not an object(evaluating 'navigation.state')-React Native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆