React-native:超级表达式必须为null或函数,而不是未定义

问题描述 投票:16回答:3

我已经看到了类似的问题,但我似乎无法确定问题。我正在使用react native v 0.27我已将所有需要的方法更改为导入。

这是我收到的错误:

enter image description here

我不知道它是否相关,但错误的第一个位置指向我的LoginComp.js文件,其中包含以下代码:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
import React, {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View,
  Image,
  TextInput,
  Button,
  TouchableHighlight
} from 'react-native';

class LoginComp extends Component {
  constructor(){
    super(props);
  }
  render() {
    return (
      <View style={{flex: 1}}>
        <View style={this.props.styles.loginLogoContainer}>
          <Image style={this.props.styles.view1logo} source={require('../imgs/Logo.png')} />
        </View>
        <View style={this.props.styles.loginContainer}>
          <Text>Użytkownik:</Text>
          <TextInput
            style={this.props.styles.defaultInput}
            placeholder="Użytkownik"
            stretch={true}
            autoComplete={false}
            autoCorrect={false}
          />
          <Text>Hasło:</Text>
          <TextInput
            style={this.props.styles.defaultInput}
            placeholder="Hasło"
            stretch={true}
            autoComplete={false}
            autoCorrect={false}
            secureTextEntry={true}
          />
        <TouchableHighlight onPress={this.props.LoginPress}>
            <Text style={this.props.styles.loginButton}>Login</Text>
          </TouchableHighlight>
        </View>
        <View style={this.props.styles.registrationWrapper}>
          <Text>- lub -</Text>
          <TouchableHighlight onPress={this.props.t_Registration}>
            <Text style={this.props.styles.registration}>Załóż nowe konto</Text>
          </TouchableHighlight>
        </View>
      </View>
    );
  }
}

module.exports = LoginComp;
reactjs react-native ecmascript-6
3个回答
47
投票

像下面一样更改您的import语句并尝试。

import React, { Component } from 'react';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  TextInput,
  Button,
  TouchableHighlight,
} from 'react-native';

构造函数也应如下所示

constructor(props){
    super(props);
}

9
投票

我遇到了同样的问题。错误导入

import React, { Component } from "react-native";

代替

import React, { Component } from "react";

看到这个答案https://stackoverflow.com/a/37676646/5367816


1
投票

就个人而言,我以另一种方式解决了这个问题:

我正在导入像import Module from "./path/to/Module.js"这样的默认模块。 但是在Module.js文件中,我省略了默认关键字: export class Module {/*...*/} - > export default class Module {/*...*/}

希望这会对某人有所帮助。 =)

© www.soinside.com 2019 - 2024. All rights reserved.