简体   繁体   English

未使用的默认导出 - React Native

[英]Unused default export - React Native

I am trying to export my main component in the App.js<\/code> file, but 'export default' in the line我正在尝试在App.js<\/code>文件中导出我的主要组件,但在行中“导出默认值”

"export default class App extends Component" “导出默认类 App 扩展组件”

<\/blockquote>

comes up unused.出现未使用。 This is the only export default statement in the project.这是项目中唯一的导出默认语句。 When I try running the project it crashes.当我尝试运行该项目时,它崩溃了。 I've posted the source code to my app.js below我已将源代码发布到我的 app.js 下面

More info: I'm using WebStorm to build this app and it's telling me the 'export default' statement is unused.更多信息:我正在使用 WebStorm 构建此应用程序,它告诉我“导出默认”语句未使用。 When I run the app I get no errors but it crashes as soon as it is opened.当我运行该应用程序时,我没有收到任何错误,但它一打开就崩溃了。

Can someone tell me what is wrong here or how to fix this issue?有人可以告诉我这里出了什么问题或如何解决这个问题吗?

 import React, {Component} from 'react'; import { StyleSheet, Text, View, ScrollView } from 'react-native'; import {LogCell} from '.\/LogCell.js'; import {Header} from 'react-native-elements'; export default class App extends Component { render() { return ( <View style={styles.container}> <Header placement="left" leftComponent={{ icon: 'date-range', color: 'white', size: 30}} centerComponent={{ text: 'Feb 2', style: { color: 'white', fontSize: 20} }} rightComponent={{ icon: 'edit', color: 'white', size: 30}} backgroundColor={"rgb(0, 100, 250)"} \/> <ScrollView style={{width: '100%', paddingLeft: '5%', paddingRight: '5%', paddingBottom: '5%'}}> <LogCell><\/LogCell> <LogCell><\/LogCell> <LogCell><\/LogCell> <\/ScrollView> <\/View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', \/\/ justifyContent: 'center',, }, });<\/code><\/pre>"

There are two ways.有两种方法。

one

import React, { Component } from 'react';
export default class App extends Component {

two

import React, { Component } from 'react';
class App extends Component {
...

export default App

You have to import like :你必须像这样导入:

import React,{Component} from 'react';

and then export default class App extends Component然后export default class App extends Component

hope it helps.希望能帮助到你。 feel free for doubts随意怀疑

您可以通过转到Preferences > Editor > Inspections > Unused symbols<\/code>并取消选中Unused global symbol<\/code>在 webstorm 中禁用此检查

"

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

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