简体   繁体   English

解析错误:反应本机示例代码出现意外令牌

[英]Parsing error: Unexpected token for react native example code

Why do I get the parsing error 为什么会出现解析错误

Parsing error: Unexpected token Props (null)

for this react native app example code? 为此反应本机应用程序示例代码? I am using the standardJS linter. 我正在使用standardJS linter。

import React, { Component } from 'react';
import {
  Text,
  View
} from 'react-native';

type Props = {}; // <-- What is wrong with that?
export default class App extends Component<Props> {
  render() {
    return (
      <View>
        <Text>
          Welcome to React Native!
        </Text>
      </View>
    );
  }
}

Unless there is a good reason why you want to send the Props, you dont need that. 除非有充分的理由要发送道具,否则就不需要。 Just remove it and keep 'Component {}' 只需将其删除并保留“ Component {}”即可

Also, it could be that you need to use static instead of type. 同样,可能是您需要使用静态而不是类型。 If you are copying this from another place, they are maybe using babel and another module. 如果要从另一个地方复制此文件,则他们可能正在使用babel和另一个模块。 This is the first time I have seen someone write this. 这是我第一次看到有人写这篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM