為什麼在點擊名稱後,我無法將設定畫面連結到登入/註冊畫面,而一直收到「undefined is not a function」的錯誤提示?
P粉399090746
P粉399090746 2023-09-16 10:45:09
0
1
675

我想做一個簡單的任務,就是從一個螢幕跳到另一個螢幕,但無論我做什麼都不起作用。我已經安裝了 react-navigation/stack 和 react-navigation/native-stack,但它們都不能與我現有的程式碼一起工作,是因為標籤頁嗎?

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import Tabs from './navigation/tabs';
import "react-native-url-polyfill/auto"
import LogInSignUp from './SettingsScreen/LogInSignUp';


const Stack = createStackNavigator();

const App = () => {
    return (
        <NavigationContainer>
          <Stack.Navigator screenOptions={{ headerShown: false }}>
            <Stack.Screen name="Home" options={{title: "Welcome"}} component={Tabs} />
            <Stack.Screen name="Settings" component={Tabs} />
            <Stack.Screen name = "LogInSignUp" component={LogInSignUp}/>
          </Stack.Navigator>
    </NavigationContainer>
  );
};

export default App;

import { Text, StyleSheet, View, Button, } from "react-native";
import { StatusBar } from "expo-status-bar";


const Settings = (navigation) => {
    return (
      <View style = {styles.container}>
        <Button title = "LogIn/SignUp" onPress={() => navigation.navigate("LogInSignUp")}></Button>
      </View>
      
    );
  }

  const styles = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
    },
    
  })

export default Settings

import React from 'react'
import { StackActions } from '@react-navigation/native';

const LogInSignUp = (navigation) => {
  return (
    <div>LogInSignUp</div>
  )
}

export default LogInSignUp

我嘗試尋找解釋這個問題的教程,他們所有的程式碼看起來都像我的程式碼,只是將名稱更換為我的 .js 文件,但什麼都不起作用。

P粉399090746
P粉399090746

全部回覆(1)
P粉342101652

你試過這個鉤子嗎

const navigation = useNavigation();

import {useNavigation} from '@react-navigation/native';

const Settings = () => {
const navigation = useNavigation();
    return (
      <View style = {styles.container}>
        <Button title = "登录/注册" onPress={() => navigation.navigate("LogInSignUp")}></Button>
      </View>
    );
  }
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板