找不到变数:反应

问题描述:

我刚开始学习反应,所以我提前道歉,如果这听起来像一个愚蠢的问题。 我想用触发一个动作的按钮做一个简单的iOS页面。 我已经按照如何上手的教程,这是我的指数代码:找不到变数:反应

'use strict'; 
var React = require('react-native'); 
var { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View, 
    TouchableHighlight, 
    Component, 
    AlertIOS // Thanks Kent! 
} = React; 

class myProj extends Component { 
render() { 
    return (
     <View style={styles.container}> 
     <Text> 
      Welcome to React Native! 
     </Text> 
     <TouchableHighlight style={styles.button} 
      onPress={this.showAlert}> 
      <Text style={styles.buttonText}>Go</Text> 
      </TouchableHighlight> 
     </View> 
    ); 
    } 

    showAlert() { 
    AlertIOS.alert('Awesome Alert', 'This is my first React Native alert.', [{text: 'Thanks'}]) 
    } 
} 

var styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    justifyContent: 'center', 
    alignItems: 'center', 
    backgroundColor: '#FFFFFF' 
    }, 
    buttonText: { 
    fontSize: 18, 
    color: 'white', 
    alignSelf: 'center' 
    }, 
    button: { 
    height: 44, 
    flexDirection: 'row', 
    backgroundColor: '#48BBEC', 
    alignSelf: 'stretch', 
    justifyContent: 'center' 
    } 
}); 

AppRegistry.registerComponent('myProj',() => myProj); 

的问题是,当我在Xcode我的设备上运行它,我得到

Can't find variable: React 
render 
main.jsbundle:1509:6 
mountComponent 
mountChildren 

我试着在网上搜索答案但找不到任何实际帮助。任何想法可能是这里的问题?

+0

尝试用'反应母语start'或'反应本地运行ios'命令 – semanser

+0

我运行项目尝试过,它显示相同的错误信息 – KeykoYume

+0

什么是你的反应原生版本? – QoP

在您必须导入原生的阵营最新版本的阵营“反应”包

import React, {Component} from 'react'; 
import { 
View, 
... 
} from 'react-native'; 
+0

谢谢!只要添加,应该是在任何使用jsx的地方 – Nickey