我想从一个屏幕导航到另一个屏幕,但我有 undefined is not an object (evaluating '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')
我想从一个屏幕的导航抽屉导航到另一个屏幕,但出现错误
类型错误:undefined 不是对象(正在计算 'this.props.navigation.navigate')
不知道为什么?
这是我的代码:
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>
)
}
使用
const {navigate} = navigation;
而不是
const {navigate} = this.props.navigation;
我想从一个屏幕的导航抽屉导航到另一个屏幕,但出现错误
类型错误:undefined 不是对象(正在计算 'this.props.navigation.navigate')
不知道为什么?
这是我的代码:
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>
)
}
使用
const {navigate} = navigation;
而不是
const {navigate} = this.props.navigation;