react native遇到的错误以及坑
持续更新中。。。
1.使用 string
报错
types are not supported by current javascript version
原因:不是 ECMAScript 6 的语法,把 JavaScript
转换成Flow
解决办法:按 Alt+Enter 来转换。
参考链接:https://intellij-support.jetbrains.com/hc/en-us/community/posts/207764165--Types-are-not-supported-by-current-JavaScript-version-after-update-to-2016-2
2.引入第三方库写法错误(是不是错误还需待定)
错误写法:
var React = require('react-native');
var {
AppRegistry,
} = React;
正确写法:
import React, {Component} from 'react';
import{AppRegistry, StyleSheet, ScrollView, Image, Text, View} from 'react-native'
3. Expected a component class, got [object Object].
原因:我的自定义组件名字是小写的,如下:
class AwesomeProject extends Component {
render() {
return (
<View style={styles.container}>
<discover_list/>
</View>
);
}
}
正确写法:
import DiscoverList from './src/page/discover_list';
class AwesomeProject extends Component {
render() {
return (
<View style={styles.container}>
<DiscoverList/>
</View>
);
}
}
即:自定义组件必须大写字母开头
网友评论