react native遇到的錯誤以及坑
持續(xù)更新中违帆。。戈钢。
1.使用 string
報錯
types are not supported by current javascript version
原因:不是 ECMAScript 6 的語法察署,把 JavaScript
轉(zhuǎn)換成Flow
解決辦法:按 Alt+Enter 來轉(zhuǎn)換涝桅。
參考鏈接: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>
);
}
}
即:自定義組件必須大寫字母開頭