2016-06-07 20 views
7

Tôi đã xem các câu hỏi tương tự nhưng tôi dường như không thể giải quyết được vấn đề. Tôi đang sử dụng phản ứng gốc v 0.27 Tôi đã thay đổi tất cả các phương thức yêu cầu của mình thành hàng nhập khẩu.Phản ứng gốc: Biểu thức siêu phải là số không hoặc hàm, không được xác định

Đây là lỗi tôi nhận được:

enter image description here

Tôi không biết nếu có liên quan của nó, nhưng vị trí đầu tiên trong những điểm lỗi đến file LoginComp.js của tôi, trong đó có đoạn mã sau:

/** 
* 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; 

Trả lời

27

Thay đổi câu lệnh nhập của bạn như dưới đây và thử.

import React, { Component } from 'react'; 

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

Cũng constructor nên như dưới đây

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

cảm ơn bạn - nó đã giải quyết được vấn đề của tôi. Nhưng tại sao nó phải như vậy? –

+5

Trong phiên bản mới nhất của phản ứng tự nhiên, 'React' và 'Component' được chuyển từ mô đun 'phản ứng gốc' sang 'phản ứng'. Vì vậy, bạn sẽ phải nhập nó bằng cách sử dụng ở trên. – Jickson

+0

và whats về bối cảnh vượt qua để constructor ?? –

1

Personnaly, tôi giải quyết vấn đề này theo một cách khác:

tôi đã nhập khẩu một module mặc định như import Module from "./path/to/Module.js".
Nhưng trong file Module.js, Tôi Bỏ qua phần từ khóa mặc định:
export class Module {/*...*/}->export default class Module {/*...*/}

Hy vọng điều này sẽ giúp một ai đó. =)

Các vấn đề liên quan