React Native Component + Navigation with Paramameters not working error undefined is not a method

v8wbuo2f  于 2023-06-06  发布在  React
关注(0)|答案(1)|浏览(106)

我有一个Reactive Component,它将数据从一个屏幕传递到另一个屏幕,试图通过Navigate(name,params)方法调用第二个组件。但它给出了一个错误,说“未定义的方法不是方法”。正在复制下面的组件代码。指导我清 debugging 误。

import React from 'react';
import {
  StyleSheet,
  Text,
  View,
  Pressable,
} from 'react-native';

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

export default function ScreenA(navigation:any) {
    const onPressHandler = () => {
        navigation.navigate("Screen_B",{ ItemName: 'Item from ScreenA', ItemId: 12 });
        // navigation.navigate("Screen_B");
    }
wgx48brx

wgx48brx1#

从功能参数中破坏导航:

import React from 'react';
import {
  StyleSheet,
  Text,
  View,
  Pressable,
} from 'react-native';

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

export default function ScreenA({navigation}) { // wrap navigation with curly brackets
    const onPressHandler = () => {
        navigation.navigate("Screen_B",{ ItemName: 'Item from ScreenA', ItemId: 12 });
    }

相关问题