程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了React Native 'TypeError: undefined is not an object (evaluating 'navigation.navigate')'大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决React Native 'TypeError: undefined is not an object (evaluaTing 'navigation.navigate')'?

开发过程中遇到React Native 'TypeError: undefined is not an object (evaluaTing 'navigation.navigate')'的问题如何解决?下面主要结合日常开发的经验,给出你关于React Native 'TypeError: undefined is not an object (evaluaTing 'navigation.navigate')'的解决方法建议,希望对你解决React Native 'TypeError: undefined is not an object (evaluaTing 'navigation.navigate')'有所启发或帮助;

这是我的第一个 React Native 项目,我被卡住了,需要帮助。以下是我的代码。我想做的是跟随。

  1. 登陆屏幕将显示所有项目的列表和底部标签菜单。
  2. 一旦有人点击项目,就会打开项目详情页面。

App.Js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow Strict-local
 */
import React from 'react';
import App from './src';
import { ProvIDer as PaperProvIDer } from 'react-native-paper';

export default App;

src/navigations/index.Js

import * as React from 'react';
import { Text,VIEw,StyleSheet,FlatList,SafeAreaVIEw } from 'react-native';
import { List,button,TexTinput,FAB,Avatar,Card,title,Paragraph } from 'react-native-paper';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator} from '@react-navigation/stack';
import ProjectList from '_scenes/projects';
import NewProject from '_scenes/projects/addproject';
import ProjectDetail from '_scenes/projects/projectdetails';
import SetTings from '_scenes/setTings';


const Tab = createBottomTabNavigator();


const Projects = ({ navigation }) => (
    <ProjectList navigation={navigation} />
);


function SetTingsScreen( { navigation} ) {
  return (
    <SetTings />
  );
}

export default function App() {
  return (
    <NavigationContainer>
      <Tab.Navigator initialRoutename="HomeScreen">
        <Tab.Screen name="Home" component={Projects} options={{ tabbarBadge: 3 }}/>
        <Tab.Screen name="SetTings" component={SetTingsScreen} options={{ tabbarBadge: 2 }}/>
      </Tab.Navigator>
    </NavigationContainer>
  );
}

src/scenes/projects/index.Js

import React,{ useEffect,useState } from 'react';
import { ActivityInDicator,Text,VIEw } from 'react-native';
import { Item,List,button } from 'react-native-paper';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator} from '@react-navigation/stack';
import NewProject from '_scenes/projects/addproject';
import ProjectDetail from './projectdetails';

ProjectList = ({ navisation }) => {

  const [isLoading,setLoading] = useState(true);
  const [data,setData] = useState([]);

  useEffect(() => {
    fetch('http://xxx.xxx.xxx.xxx/projects')
      .then((responsE) => response.Json())
      .then((Json) => setData(Json))
      .catch((error) => console.error(error))
      .finally(() => setLoading(false));
  },[]);

  function Projects ( {navigation }) {
    return (
      <VIEw style={{ flex: 1,padding: 24 }}>
        <FlatList
        data={data} 
        keyExtractor={({ ID },indeX) => ID}
        renderItem={renderProject}
        />
      </VIEw>
    )
    }

  const renderProject = ({ navigation,item }) => (
    <List.Item
    title={item.title}
    description={item.description}
    onPress={() => navigation.navigate('ProjectDetails')}
    />
  );

  const AddProject = ({ navigation }) => (
      <NewProject />
  );

  function ProjectDetails({navigation}) {
    return (
      <ProjectDetail />
    );
  }

  function Chat({navigation}) {
    return (
      <VIEw>
        <Text>Chat</Text>
      </VIEw>
    );
  }



  const Stack = createStackNavigator();
  return (
    <Stack.Navigator>
      <Stack.Screen title="Home" name="Home" component={Projects} options={{headerShown: falsE}}/>
      <Stack.Screen title="Add Project" name="AddProject" component={AddProject} />
      <Stack.Screen title="Project Details" name="ProjectDetails" component={ProjectDetails} />
      <Stack.Screen title="Chat" name="Chat" component={Chat} />      
    </Stack.Navigator>

    );
};

export default ProjectList;

如果您看到“renderProject”,我想在点击时导航到“ProjectDetails”。但我收到错误 'TypeError: undefined is not an object (evaluaTing 'navigation.navigate')' 让我知道出了什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的React Native 'TypeError: undefined is not an object (evaluating 'navigation.navigate')'全部内容,希望文章能够帮你解决React Native 'TypeError: undefined is not an object (evaluating 'navigation.navigate')'所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。