TypeError:undefined不是一个对象(正在评估“ navigation.push”)React Native

亨里克

所以这是错误: 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;

问题是什么?:)

亨里克

您应该navigation在const内部定义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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

React Native:TypeError:undefined不是一个对象(评估'this.props.navigation.navigate')

React Native:undefined 不是一个对象(评估'_this2.props.navigation.navigate')

React Native undefined不是一个对象(评估“ props.navigation.toggleDrawer”)

Undefined 不是一个对象(评估'this.props.navigation.navigate')React native

React Native得到TypeError:undefined不是一个对象(正在评估'_this.state.apiData.items.map')

react-native:undefined中的抽屉导航错误不是一个对象(评估'_this.props.navigation.openDrawer()')

React Native:TypeError:undefined不是一个对象(评估'_this.props.data.map')

TypeError:undefined不是React Native中的一个对象(评估'this.state.Gas')

TypeError:undefined不是React Native中的一个对象(评估'this.state.Gase')

React Native TypeError:undefined 不是一个对象(评估'_ref.item')

React Native:undefined 不是对象(评估“props.navigation.navigate”)

React Native,TypeError:undefined不是一个对象,当它是

React Native:React Navigation StackNavigator 不工作。得到错误:“未定义不是一个对象(评估'this.props.navigation.navigate')”

react-navigation:undefined不是一个对象(评估'Object.keys(routeConfigs)')

React Native:'undefined 不是一个对象(评估'_react3.PropTypes.bool')

React Native undefined不是一个对象(评估“ Mapbox.GL.UserTrackingModes”)

undefined 不是一个对象(评估 'Context._context') - React Native

Undefined 不是一个评估 title.length React Native 的对象

undefined 不是一个对象(评估'ToolbarAndroid.propTypes')react-native-general-calendars

错误 react-native-video : undefined 不是一个对象(评估 'RCTVideoInstance.Constants')

undefined 不是一个对象(评估 'this.onbuffer') React Native

React Native,navigation.navigate不是一个函数

react-native-navigation给出错误“未定义不是对象(正在评估'_this.props.navigation.navigate')”

react-native: undefined 不是带有反应导航的对象(评估“_this2.props.navigation”)

undefined不是对象(评估'_this2.props.navigation.navigate')-React Native

React-native:undefined不是对象(评估'_this3.props.navigation.navigate')

TypeError:undefined 不是 React Native 中的对象(正在评估“addTodo(title, description).then”)

this.props.navigation.toggedrawer不是一个函数-React Native 0.59.9 React Navigation 3.11.0

React Native Render使用map渲染一个对象:undefined不是对象(评估“ currentLocation.coords”)