所以这是错误:TypeError: undefined is not an object (evaluating 'navigation.push')
我使用 React Navigation 5 和。这是我的 App.js:
import React, { useState, useEffect } from 'react';
import { Text, View, StyleSheet, TouchableOpacity, FlatList, Alert} from 'react-native';
const MyApp = ({navigation}) => {
return(
<Button
onPress={() => navigation.push('Information')}
title="Get Information"
/>
);
}
export default MyApp;
有什么问题? :)
答案 0 :(得分:0)
您应该在 const navigation
中定义 MyApp
!
你也应该导入 useNavigation
import React, { useState, useEffect } from 'react';
import { Text, View, StyleSheet, TouchableOpacity, FlatList, Alert} from 'react-native';
import { useNavigation } from '@react-navigation/native';
const MyApp = () => {
const navigation = useNavigation();
return(
<Button
onPress={() => navigation.push('Information')}
title="Get Information"
/>
);
}
export default MyApp;
感谢您的帮助Allandiego