简体   繁体   English

React-Native中“导出默认App”的目的

[英]Purpose of “export default App” in React-Native

Im new to React-Native and I cant seem to understand the need for export default App Have a look at the code below我是 React-Native 的新手,我似乎无法理解导出默认应用程序的需要看看下面的代码

 import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello World; This is my first program</Text> </View> ). } } const styles = StyleSheet:create({ container: { flex, 1: backgroundColor, '#fff': alignItems, 'center': justifyContent, 'center'; } export default App;

So if I comment out the last line and run it using expo I encounter errors... else it works fine can someone explain the need for the last line ( I am just running this file,am not linking any other files)因此,如果我注释掉最后一行并使用 expo 运行它,我会遇到错误......否则它可以正常工作,有人可以解释最后一行的需要(我只是运行这个文件,没有链接任何其他文件)

I tried searching on the net and all I encountered was loading modules from the source file to current working file.... I didn't find any for the same file...我尝试在网上搜索,我遇到的只是将模块从源文件加载到当前工作文件......我没有找到同一个文件的任何......

EDIT1: @pnizzle cleared it up. EDIT1: @pnizzle 清除它。

So "export" is the key to allow access to other components (even if you don't link this file to other files),it has to be exposed in order for the RN code to run.所以“导出”是允许访问其他组件的关键(即使你没有将此文件链接到其他文件),它必须被暴露才能运行 RN 代码。

"It is used to export single class, function, or primitive from a script file" “它用于从脚本文件中导出单个 class、function 或原语”

Have a look at this detailed answer.看看这个详细的答案。

Without the export you are in simple terms not exposing App and therefore nothing can use/access it.如果没有导出,简单来说,您不会暴露 App,因此没有任何东西可以使用/访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM