【问题标题】:Unused default export - React Native未使用的默认导出 - React Native
【发布时间】:2020-05-21 03:51:27
【问题描述】:

我正在尝试在App.js 文件中导出我的主要组件,但在该行中“导出默认值”

"导出默认类App扩展组件"

未使用。这是项目中唯一的导出默认语句。当我尝试运行该项目时,它崩溃了。我已将源代码发布到下面的 app.js 中

更多信息:我正在使用 WebStorm 构建此应用程序,它告诉我“导出默认”语句未使用。当我运行该应用程序时,我没有收到任何错误,但它一打开就崩溃了。

谁能告诉我这里出了什么问题或如何解决这个问题?

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',,
    },
});

【问题讨论】:

  • 崩溃时看到的错误是什么?

标签: javascript reactjs react-native expo


【解决方案1】:

有两种方法。

一个

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

两个

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

export default App

【讨论】:

  • @jimmyruby 你可能没有做对。看看我修改后的代码。
  • @jimmyruby 我复制并粘贴了您的代码并对其进行了测试,但没有错误。是否要退出并再次尝试运行?
  • @jimmyruby 如果您正在使用 expo,请尝试使用此语句。 expo start -c
【解决方案2】:

你必须像这样导入:

import React,{Component} from 'react';

然后export default class App extends Component

希望对您有所帮助。如有疑问,请随意

【讨论】:

  • 你从哪里导入的?
  • 在上面的源代码中我在第一行导入了它
  • 不,我的意思是,你在哪里导入的应用程序,必须在其他页面中
  • 据我所知,如果 App 是要导出的默认类,则不必导入它。这是在 App.js 文件中
猜你喜欢
  • 2019-05-08
  • 2021-05-20
  • 2017-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-07
  • 2020-07-28
相关资源
最近更新 更多