2016-06-07 94 views
7

我看過類似的問題,但我似乎無法確定問題。 我正在使用react native v 0.27 我已將所有需要的方法更改爲導入。React-native:超級表達式必須爲空或函數,而不是未定義

這是我收到的錯誤:

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; 

回答

27

更改您的導入語句,如下所示,並嘗試。

import React, { Component } from 'react'; 

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

而且構造應該有如下

constructor(props){ 
    super(props); 
} 
+0

謝謝 - 它解決了我的問題。但爲什麼它必須這樣呢? –

+5

在反應本機的最新版本中,'React'和'Component'從'react-native'移動到'react'模塊。所以你將不得不使用上面的方式導入它。 – Jickson

+0

和上下文傳遞給構造函數? –

1

Personnaly,我解決了另一種方式這個問題:

我導入默認模塊像import Module from "./path/to/Module.js"
但在Module.js文件,我中省略了默認的關鍵字
export class Module {/*...*/}- >export default class Module {/*...*/}

希望這會幫助別人。 =)

相關問題