Reactjs 从菜单项导航
我试图让一个菜单项导航到另一个页面,但由于某种原因,它不允许我这样做。我有点困惑你是怎么做的,欢迎任何帮助 在此处导入:Reactjs 从菜单项导航,reactjs,Reactjs,我试图让一个菜单项导航到另一个页面,但由于某种原因,它不允许我这样做。我有点困惑你是怎么做的,欢迎任何帮助 在此处导入: import { NavigationScreenProp } from "react-navigation"; 以下是更多代码: interface NotificationDropdownProps { navigation: NavigationScreenProp<any, any>; } 错误: undefined is
import { NavigationScreenProp } from "react-navigation";
以下是更多代码:
interface NotificationDropdownProps {
navigation: NavigationScreenProp<any, any>;
}
错误:
undefined is not an object(evaluating'_this2.props.naviagtion.navigate)
调用函数时:
function renderNotification(notification: INotification) {
return (
<MenuOption
onSelect={() => {
if (notification.type == INotificationType.SYSTEM) {
this.testFunction();
}
}}
>
<View style={[styles.notificationContainer]}>
<View style={styles.iconArea}>
<View style={[styles.iconCircle]}>
<Icon
name={this.getIconType(notification.type)}
color={this.notificationColor(notification.type)}
size={26}
/>
</View>
</View>
<View>
<Text>{notification.text}</Text>
<Text>
{this.getDate(new Date(notification.dateCreated))}
</Text>
</View>
</View>
</MenuOption>
);
}
<View>
<Text>
Notifications
</Text>
{this.props.notifications.length > 0 ? (
<FlatList
contentContainerStyle={{ borderRadius: 10 }}
data={this.props.notifications.slice(0, 5)}
renderItem={({ item }) => this.renderNotification(item)}
keyExtractor={this.keyExtractor}
/>
) : (
<Text>No Notifications!</Text>
)}
</View>;
通知
{this.props.notifications.length>0(
此.renderNotification(项目)}
keyExtractor={this.keyExtractor}
/>
) : (
没有通知!
)}
;
尝试使用箭头函数,以避免使用函数的上下文
testFunction=()=>{
this.props.navigation.navigate('NextPage'))
};
谢谢您的帮助,但我收到了该代码的错误:属性“navigation”在类型“Readonly&Readonly”上不存在。ts(2339)请将所有代码和错误放在您的帖子中,以便我们能够解决您的问题:)我在那里添加了更多代码,希望这能有所帮助。你确定你有导航道具吗?你能console.log(this.props)
<View>
<Text>
Notifications
</Text>
{this.props.notifications.length > 0 ? (
<FlatList
contentContainerStyle={{ borderRadius: 10 }}
data={this.props.notifications.slice(0, 5)}
renderItem={({ item }) => this.renderNotification(item)}
keyExtractor={this.keyExtractor}
/>
) : (
<Text>No Notifications!</Text>
)}
</View>;