当我什至不使用 TypeScript 时,为什么会收到一条错误消息,指出应进行属性分配? [英] Why am I getting an error that says Property assignment expected when I'm not even using TypeScript?

查看:56
本文介绍了当我什至不使用 TypeScript 时,为什么会收到一条错误消息,指出应进行属性分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是

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

const ComponentsScreen = () => {
  return {
    <View>
        <Text style={styles.testStyle}>This is the components screen</Text>
    </View>
    };
};

const styles = StyleSheet.create({
    testStyle: {
        fontSize: 30
    }
});

export default ComponentsScreen;

我收到一条错误消息,显示在我的开始视图标记处预期属性分配,在我关闭视图标记处和关闭 ComponentsScreen 的括号处出现声明或语句预期错误,以及在关闭我的 return 语句的括号处出现预期错误.有什么解决办法吗?

I am getting an error which says Property Assignment Expected at my opening View tag, Declaration or Statement expected error at my closing View tag and at the bracket which closes ComponentsScreen, and Expression expected at the bracket closing my return statement. Any solutions?

推荐答案

在组件屏幕中 jsx 在括号中使用 return 语句而不是花括号 {} .

In component screen jsx uses return statment in parantheses rather than curly braces {} .

所以只需替换这个:

const ComponentsScreen = () => {
  return (
    <View>
        <Text style={styles.testStyle}>This is the components screen</Text>
    </View>
    );
};

希望有帮助.不用怀疑

这篇关于当我什至不使用 TypeScript 时,为什么会收到一条错误消息,指出应进行属性分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆