简体   繁体   中英

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

 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)

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.

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.

"It is used to export single class, function, or primitive from a script file"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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