【发布时间】:2017-12-14 17:00:55
【问题描述】:
我正在尝试学习 React Native,但我什至无法返回一个简单的函数。部署时,我的 IOS sim 卡中出现意外令牌错误或“未返回有效的反应元素”错误。
我正在尝试了解如何返回不同的函数,但这些教程的语法似乎与 Facebook 教程上的原始入门页面不同:
http://facebook.github.io/react-native/releases/0.20/
这就是我所拥有的:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
//import AwesomeComponent from "./awesome.js";
export default class SkysReact extends Component {
render() {
return this.test();
// return (<View style={styles.container}>
// <Text style={styles.welcome}>
// Welcome to Skylars React Native!
// </Text>
// <Text style={styles.instructions}>
// This is a sandbox.
// </Text>
// </View>);
}
var test = function() {
console.log("hello world");
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#000',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
color: '#333333'
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('SkysReact', () => SkysReact);
如何在我的文件中定义不同的函数来操作?
【问题讨论】:
-
如果你正在学习 react 或 react-native,你应该从 up-to-date version 和 up-to-date tutorial 开始。您的链接指的是一个两年前的版本,对于像这样的尖端技术来说已经过时了。 “不同的语法”可能是ES2015 (also known as ES6)?这也绝对值得学习。
标签: javascript ios facebook reactjs react-native