特别是在这样的地方
componentDidMount() {
this._getCoords();
}
此._getCoords
之前的“ {”被标记为错误。
constructor(props)(
super(props);
this._getCoords = this._getCoords.bind(this);
this.state = {
position: null
};
有什么原因吗?而不是接受{表示有效,而是说一个)。但是,当我提出该建议时,代码显然会中断。
我尝试使用“ ES7 React / Redux / GraphQL / React-Native代码段”,“ ES6 / es7的React-Native / React / Redux代码段”和“ React Native Tools”之类的工具...但是他们似乎都不允许我正确编写React Native代码。
我尝试打开和关闭扩展名,而没有发现太多差异。似乎VSCode希望我纯粹使用JavaScript进行编码
constructor(props)(
super(props);
this._getCoords = this._getCoords.bind(this);
this.state = {
position: null
};
componentDidMount() {
this._getCoords();
}
如前所述,我看到的一般错误是“;”预期或“)预期”,而不是接受React Native的适当语法。此外,尽管这更直观,但各种命令的颜色编码本质并未出现。
import {MapView } from 'react-native-maps';
constructor(props){
super(props);
this._getCoords = this._getCoords.bind(this);
this.state = { position: null };
}
componentDidMount() { this._getCoords(); }
答案 0 :(得分:0)
包含构造函数时,必须使用middle brackets
而不是small brackets
。
(=> {//
{
代替(
JavaScript基于Java,是一种面向对象的语言。因此,您在类中创建对象。要使用构造函数,必须使用一个类。
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
position: null
};
}
componentDidMount() {
this._getCoords();
}
_getCoords() {
alert("_getCoords")
}
render() {
return(<View><Text>Basic Screen </Text> </View>);
}
}