我以前在react js上工作过&我是react native的新手我正在尝试在我的应用程序中的组件之间导航我正在使用reactnavigation我不知道这是最简单的方法吗
我有app.js和Dashbord.js
- 应用程序. js**
function HomeScreen(navigation) {
return (
<View style={styles.prheight}>
<View style={styles.prheight}>
<Text style={styles.r}>Sukhprasavam</Text>
</View>
<View style={styles.buttonw}>
<Button
color="#7743DB"
title="Lets Go"
onPress={() => navigation.navigate('Dashbord')}
/>
</View>
</View>
);
}
const Stack = createNativeStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
options={{headerShown: false}}
name="Home"
component={HomeScreen}
/>
<Stack.Screen name="Dashbord" component={Dashbord} />
</Stack.Navigator>
</NavigationContainer>
);
}
- Jmeter 板**
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
export default function Dashbord() {
return (
<View style={styles.prheight}>
<View style={styles.prheight}>
<Text style={styles.r}>dada</Text>
</View>
<View style={styles.buttonw}>
<Button
color="#7743DB"
title="Lets Go"
/>
</View>
</View>
);
}
这一行onPress={() => navigation.navigate('Dashbord')}
上的错误i am getting is undefined is not a funtion
1条答案
按热度按时间mqkwyuun1#
对
HomeScreen
函数稍作修改:HomeScreen(navigation)
至HomeScreen({ navigation })
如果要使用
HomeScreen(navigation)
,只需更改onPress
函数:onPress={() => navigation.navigate('Dashbord')}
至onPress={() => navigation.navigation.navigate('Dashbord')}