我看到过类似的问题,但我似乎无法确定问题所在.

以下是我收到的错误:

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;

推荐答案

如下图所示更改导入语句,然后重试.

import React, { Component } from 'react';

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

另外,构造函数应该如下所示

constructor(props){
    super(props);
}

React-native相关问答推荐

如何在EXPO路由中重置导航

使用动画标记时如何优化react 本机 map 性能

新的 react-native ios 应用程序没有构建?

react-native redux 和 ListView

React-native android 样式化 textInput

你如何在生产模式下运行 react-native 应用程序?

Visual Studio 代码错误:-Failed to start flow Error: Wrong version of Flow. The config specifies version ^0.92.0 but this is version 0.95.1

ReactNative FlatList 一次渲染所有元素?

当组件在react-native 中重新呈现时,动态不透明度不会改变

ScrollView visible Scroll Bar

大型列表的 React-Native FlatList 性能问题

使用 expo SDK react-native ios 应用程序的 Info.plist 文件

[React-Native][Jest]SyntaxError: Unexpected token import

如何将时刻日期转换为字符串并删除时刻对象

react-native 中的倒数计时器

无法在react-native元素中扩展 Zip

ReactNative TextInput 不可见 iOS

使用 React Native 一次启动多个 Animated.timing

xcode 使用错误的 node.js 版本

如何在 React-Native 中停止touch 事件传播