【发布时间】:2022-01-19 06:08:47
【问题描述】:
大家好,我想在我的项目中使用 ViewCart 文件作为组件,但它没有显示,不知道为什么?但是当我在我的 App.js 文件中的整个代码上编写它时,它工作正常。请告诉我为什么会这样,并告诉我如何在我的项目中使用 Viewcart 文件作为组件。如果您有任何疑问,请随时提问。
// ViewCart.js
我想在我的 App.js 文件中使用这个文件作为组件
import * as React from 'react';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
function HomeScreen() {
return (
<View >
<Text>Home Screen</Text>
</View>
);
}
const Stack = createNativeStackNavigator();
function ViewCart() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default ViewCart;
App.js
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import ViewCart from "./screens/ViewCart";
function App() {
return (
<View style={styles.container}>
<ViewCart />
{/* <StatusBar style="auto" /> */}
</View>
);
}
const styles = StyleSheet.create({
// container: {
// flex: 1,
// backgroundColor: "#fff",
// alignItems: "center",
// justifyContent: "center",
// },
});
export default App;
【问题讨论】:
标签: javascript react-native react-navigation