我试图在我的手机上运行这个反应原生跨平台js但我得到这个错误

时间:2016-07-15 15:46:42

标签: android react-native

http://i.stack.imgur.com/MZCzT.png

当我运行跨平台js时,我得到上述错误。这是否会给任何人带来任何危险信号?下面是跨平台js。虽然最后一个代码片段是index.android.js



var React = require('react-native');
//import React from 'react';

var {
//import {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View
} = React;
//} from 'react-native';

var AwesomeProject = React.createClass ({
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Shake or press menu button for dev menu
        </Text>
      </View>
    );
  }
});

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

module.exports = AwesomeProject;
&#13;
&#13;
&#13;

&#13;
&#13;
var React = require('react-native');
var { AppRegistry } = React;
var HelloWorldApp = require('./AwesomeProject.js');
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您正在从react-native导入Component。但是在最新的react-native版本中,您必须从react包导入Component。更改您的import语句如下。

import React, {Component} from 'react';
import { AppRegistry, StyleSheet, Text, View} from 'react-native';