[英]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.