简体   繁体   English

我想从一个屏幕导航到另一个屏幕,但我有 undefined is not an object (评估'this.props.navigation.navigate')

[英]I want to navigate from one screen to another screen but I am having undefined is not an object (evaluating 'this.props.navigation.navigate')

I want to navigate from navigation drawer one screen to another screen but I am having an error我想从导航抽屉的一个屏幕导航到另一个屏幕,但出现错误

Type Error: undefined is not an object (evaluating 'this.props.navigation.navigate')类型错误:未定义不是 object(评估“this.props.navigation.navigate”)

don't know why?不知道为什么?

Here is my code:这是我的代码:

import React, { useState } from 'react';
import { View } from 'react-native';
import { Drawer, Appbar, Divider } from 'react-native-paper';
import style from './menu.style';
import popularposts from './popularposts';

export default Menu = ({onMenuToggle, options, navigation}) => {
    const [active, setActive] = useState('home');
    const {navigate} = this.props.navigation;
    return (
       <View style={style.container}>
       <Appbar.Header>
            <Appbar.Content></Appbar.Content>
            <Appbar.Action icon="close" onPress={onMenuToggle} />
        </Appbar.Header>
            <Drawer.Section>
             <Drawer.Item
                label="Popular Post"
                active={active === 'first'}
                onPress={() => navigate('popularposts')}
                />
                <Drawer.Item
                label="Important Dates/ Events"
                active={active === 'second'}
                onPress={() => { setActive('second'); }}
                />
                <Divider />
                <Drawer.Item
                label="SIGN OUT"
                active={active === 'fourth'}
                onPress={() => { setActive('fourth'); }}
                />
            </Drawer.Section>
       </View>
    )
}

Use利用

const {navigate} = navigation;

Instead of代替

const {navigate} = this.props.navigation;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在本机反应中与此this.props.navigation.navigate有问题 - I am having issues with this.props.navigation.navigate in react native React Native:TypeError:undefined不是对象(评估'this.props.navigation.navigate') - React Native: TypeError: undefined is not an object (evaluating 'this.props.navigation.navigate') Undefined 不是 React Native 上的 object(评估“this.props.navigation.navigate”) - Undefined is not an object (evaluating 'this.props.navigation.navigate') on React Native 错误:未定义不是 object(评估 this.props.navigation.navigate) - Error: undefined is not an object (evaluating this.props.navigation.navigate) React Native: TypeError: undefined is not an object (evalating 'this.props.navigation.navigate') 当点击按钮。 为什么? - React Native: TypeError: undefined is not an object (evaluating 'this.props.navigation.navigate') when click on button. Why? 反应本机导航(未定义不是对象.. this.props.navigation.navigate - React native navigation (undefined is not an object .. this.props.navigation.navigate 当我在验证后尝试导航时,未定义不是对象(评估 _this props.navigation.navigate) - undefined is no an object( evaluating _this props.navigation.navigate) when i try to navigate after validate 如何修复“未定义不是对象(评估 &#39;navigation.navigate&#39;)”? - How can I fix the "undefined is not an object (evaluating 'navigation.navigate')"? 使用reactnavigation时出错:undefined不是对象(评估_this2.props.navigation.navigate) - error using reactnavigation: undefined is not object (evaluating _this2.props.navigation.navigate) React-Native:this.props.navigation.navigate未定义 - React-Native : this.props.navigation.navigate undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM